CentOS 7.4 DPDK 18.11 编译

环境:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

处理器: Intel(R) Xeon(R) Silver 4210 CPU @ 2.20GHz
CPU(s): 40
NUMA node0 CPU(s): 0-9,20-29
NUMA node1 CPU(s): 10-19,30-39
内存: 128G
系统: CentOS 7.4
网卡: X722 已绑定
[root@localhost ~]# lshw -c network -businfo
Bus info Device Class Description
=======================================================
pci@0000:03:00.0 enp3s0f0 network I350 Gigabit Network Connection
pci@0000:03:00.1 enp3s0f1 network I350 Gigabit Network Connection
pci@0000:03:00.2 enp3s0f2 network I350 Gigabit Network Connection
pci@0000:03:00.3 enp3s0f3 network I350 Gigabit Network Connection
pci@0000:1a:00.0 network Ethernet Connection X722 for 10GbE SFP+
pci@0000:1a:00.1 network Ethernet Connection X722 for 10GbE SFP+
pci@0000:1a:00.2 network Ethernet Connection X722 for 10GbE SFP+
pci@0000:1a:00.3 network Ethernet Connection X722 for 10GbE SFP+
pci@0000:3c:00.0 enp60s0 network Ethernet Controller XL710 for 40GbE backplane
pci@0000:86:00.0 enp134s0 network Ethernet Controller XL710 for 40GbE backplane
[root@localhost ~]#

所需的 rpm

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[root@localhost CentOS_7.4]# md5sum  *
4c254f0a3581e1864e1b81dfc1c051de boost-devel-1.53.0-27.el7.x86_64.rpm
16522135e6954a4980a2de757330428e cmake-2.8.12.2-2.el7.x86_64.rpm
f7cc74303ef78c93c22b804328117f73 glib2-devel-2.50.3-3.el7.x86_64.rpm
4de80c60ca7b96e7e718ce2897626742 kernel-3.10.0-693.el7.x86_64.rpm
76356df962650b8a17b7a0f78cd2d7f2 kernel-devel-3.10.0-693.el7.x86_64.rpm
6169a46e888b0f641e2dea9096656a50 kernel-headers-3.10.0-693.el7.x86_64.rpm
0505c3becb716af807763337607c977d libpcap-1.5.3-9.el7.x86_64.rpm
2d7409edabe31140d6adc62dce01ae3b libpcap-devel-1.5.3-9.el7.x86_64.rpm
9ef4f952cb71ccafb59f1549062cd6bc ncurses-devel-5.9-13.20130511.el7.x86_64.rpm
e9f2b57d8bd84002ad13f07fb41ee498 numactl-devel-2.0.9-6.el7_2.x86_64.rpm
b5ec3c79212e2f6ed1d8983ca618d34d numactl-libs-2.0.9-6.el7_2.x86_64.rpm
8cb1aafaf411285e9cb613d0833e0714 pcre-8.32-17.el7.x86_64.rpm
e161c3c79eab222ae1ff185aa5f22e86 pcre-devel-8.32-17.el7.x86_64.rpm
005865c96dd1e2dadb10fd25824314ee readline-6.2-10.el7.x86_64.rpm
2aa5709b7a5a068626c615be6bc2c70f readline-devel-6.2-10.el7.x86_64.rpm
[root@localhost CentOS_7.4]#

源码 编译 一气呵成!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
tar xf dpdk-18.11.11.tar.xz
cd dpdk-stable-18.11.11/
export EXTRA_CFLAGS='-O0 -g'

安装到一个x86_64-native-linuxapp-gcc目录
make config T=x86_64-native-linuxapp-gcc && make && make install T=x86_64-native-linuxapp-gcc

#安装到系统/usr目录
make config T=x86_64-native-linuxapp-gcc && make && make install




其他 帮助
make help

设置 RTE 环境变量, 为后期 DPDK 开发准备.

1
2
export RTE_SDK="/root/git/dpdk/dpdk-stable-18.11.11/"
export RTE_TARGET=x86_64-native-linuxapp-gcc

查看编译结果

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[root@localhost dpdk-stable-18.11.11]# ll x86_64-native-linuxapp-gcc/app/ -h
total 229M
-rwxr-xr-x 1 root root 33M Mar 18 11:20 dpdk-pdump
-rw-r--r-- 1 root root 4.7M Mar 18 11:20 dpdk-pdump.map
-rwxr-xr-x 1 root root 28K Mar 18 11:17 dpdk-pmdinfogen
-rwxr-xr-x 1 root root 33M Mar 18 11:20 dpdk-procinfo
-rw-r--r-- 1 root root 4.7M Mar 18 11:20 dpdk-procinfo.map
-rwxr-xr-x 1 root root 34M Mar 18 11:20 dpdk-test-crypto-perf
-rw-r--r-- 1 root root 4.7M Mar 18 11:20 dpdk-test-crypto-perf.map
-rwxr-xr-x 1 root root 34M Mar 18 11:20 dpdk-test-eventdev
-rw-r--r-- 1 root root 4.8M Mar 18 11:20 dpdk-test-eventdev.map
-rwxr-xr-x 1 root root 33M Mar 18 11:20 testbbdev
-rw-r--r-- 1 root root 4.7M Mar 18 11:20 testbbdev.map
-rwxr-xr-x 1 root root 36M Mar 18 11:20 testpmd
-rw-r--r-- 1 root root 5.1M Mar 18 11:20 testpmd.map
[root@localhost dpdk-stable-18.11.11]#

查看 引用 动态库

1
2
3
4
5
6
7
8
9
10
11
[root@localhost dpdk-stable-18.11.11]# ldd x86_64-native-linuxapp-gcc/app/testpmd
linux-vdso.so.1 => (0x00007ffcc3ffc000)
librt.so.1 => /lib64/librt.so.1 (0x00007f3ecefb8000)
libm.so.6 => /lib64/libm.so.6 (0x00007f3ececb6000)
libnuma.so.1 => /lib64/libnuma.so.1 (0x00007f3eceaa9000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007f3ece8a5000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f3ece689000)
libc.so.6 => /lib64/libc.so.6 (0x00007f3ece2c5000)
/lib64/ld-linux-x86-64.so.2 (0x00005605431a9000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f3ece0af000)
[root@localhost dpdk-stable-18.11.11]#

查看所有 i40e_flow_ 相关驱动层 符号

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
[root@localhost app]#  nm -Aa testpmd| grep i40e_flow_
testpmd:0000000000b65607 T i40e_flow_add_del_fdir_filter
testpmd:0000000000b6b321 t i40e_flow_check_raw_item
testpmd:0000000000b7c51e t i40e_flow_create
testpmd:0000000000ad7b34 t i40e_flow_ctrl_get
testpmd:0000000000ad7c3a t i40e_flow_ctrl_set
testpmd:0000000000b7c777 t i40e_flow_destroy
testpmd:0000000000b7c902 t i40e_flow_destroy_ethertype_filter
testpmd:0000000000b7ca35 t i40e_flow_destroy_tunnel_filter
testpmd:0000000000b5c96a t i40e_flow_fdir_fill_eth_ip_head
testpmd:0000000000b67325 t i40e_flow_fdir_filter_programming
testpmd:0000000000b5c910 t i40e_flow_fdir_find_customized_pctype
testpmd:0000000000b6bf8d t i40e_flow_fdir_get_pctype_value
testpmd:0000000000b7e0ba t i40e_flow_flush
testpmd:0000000000b7e349 t i40e_flow_flush_ethertype_filter
testpmd:0000000000b7e203 t i40e_flow_flush_fdir_filter
testpmd:0000000000b7e51b t i40e_flow_flush_rss_filter
testpmd:0000000001079880 R i40e_flow_ops
testpmd:0000000000b6aca4 t i40e_flow_parse_attr
testpmd:0000000000b6b0b7 t i40e_flow_parse_ethertype_action
testpmd:0000000000b6b27d t i40e_flow_parse_ethertype_filter
testpmd:0000000000b6ae39 t i40e_flow_parse_ethertype_pattern
testpmd:0000000000b70243 t i40e_flow_parse_fdir_action
testpmd:0000000000b7050e t i40e_flow_parse_fdir_filter
testpmd:0000000000b6c087 t i40e_flow_parse_fdir_pattern
testpmd:0000000000b7acfe t i40e_flow_parse_gtp_filter
testpmd:0000000000b7aa03 t i40e_flow_parse_gtp_pattern
testpmd:0000000000b7a95f t i40e_flow_parse_mpls_filter
testpmd:0000000000b79149 t i40e_flow_parse_mpls_pattern
testpmd:0000000000b790a5 t i40e_flow_parse_nvgre_filter
testpmd:0000000000b74cdd t i40e_flow_parse_nvgre_pattern
testpmd:0000000000b7afdd t i40e_flow_parse_qinq_filter
testpmd:0000000000b7ada2 t i40e_flow_parse_qinq_pattern
testpmd:0000000000b7b1f0 t i40e_flow_parse_rss_action
testpmd:0000000000b7b081 t i40e_flow_parse_rss_pattern
testpmd:0000000000b70683 t i40e_flow_parse_tunnel_action
testpmd:0000000000b74c39 t i40e_flow_parse_vxlan_filter
testpmd:0000000000b70998 t i40e_flow_parse_vxlan_pattern
testpmd:0000000000b6bb57 t i40e_flow_set_fdir_flex_msk
testpmd:0000000000b6b809 t i40e_flow_set_fdir_flex_pit
testpmd:0000000000b6bc4f t i40e_flow_set_fdir_inset
testpmd:0000000000b6b63c t i40e_flow_store_flex_mask
testpmd:0000000000b6b44b t i40e_flow_store_flex_pit
testpmd:0000000000b7c24c t i40e_flow_validate
testpmd:0000000000b93c3d T rte_pmd_i40e_flow_add_del_packet_template
testpmd:0000000000b8e3ab T rte_pmd_i40e_flow_type_mapping_get
testpmd:0000000000b8e31a T rte_pmd_i40e_flow_type_mapping_reset
testpmd:0000000000b8e4a6 T rte_pmd_i40e_flow_type_mapping_update
[root@localhost app]#

验证

使用 testpmd 演示 ipv4 + tcp + raw 匹配 功能.

匹配 HTTP POST 请求报文, 存放于 指定队列.

1
2
3
4
5
6
7
8
[root@localhost dpdk-stable-18.11.11]# cd x86_64-native-linuxapp-gcc/app/
[root@localhost app]#
./testpmd -l 0-9 -n 4 -- -i --nb-cores=8 --rxq=4 --txq=4 --disable-rss --pkt-filter-mode=perfect
set verbose 1
set fwd rxonly
flow create 0 ingress pattern eth / ipv4 / tcp / raw relative is 1 offset is 0 pattern is POST / end actions queue index 1 / end
start
flow list 0

支持 SBP/APD_CRC

SBP: Enable Save bad packet
APD_CRC: Disable NIC_HW_APPEND_CRC

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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
diff --git a/.gitignore b/.gitignore
deleted file mode 100644
index e69de29..0000000
diff --git a/drivers/net/i40e/i40e_ethdev.c b/drivers/net/i40e/i40e_ethdev.c
index 557299e..545e775 100644
--- a/drivers/net/i40e/i40e_ethdev.c
+++ b/drivers/net/i40e/i40e_ethdev.c
@@ -3469,6 +3469,7 @@ static int i40e_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
DEV_RX_OFFLOAD_SCATTER |
DEV_RX_OFFLOAD_VLAN_EXTEND |
DEV_RX_OFFLOAD_VLAN_FILTER |
+ DEV_RX_OFFLOAD_SAVE_BAD_PACKET |
DEV_RX_OFFLOAD_JUMBO_FRAME;

dev_info->tx_queue_offload_capa = DEV_TX_OFFLOAD_MBUF_FAST_FREE;
@@ -3486,6 +3487,8 @@ static int i40e_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
DEV_TX_OFFLOAD_IPIP_TNL_TSO |
DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
DEV_TX_OFFLOAD_MULTI_SEGS |
+ DEV_TX_OFFLOAD_DISABLE_APPEND_FRAME |
+ DEV_TX_OFFLOAD_DISABLE_APPEND_CRC |
dev_info->tx_queue_offload_capa;
dev_info->dev_capa =
RTE_ETH_DEV_CAPA_RUNTIME_RX_QUEUE_SETUP |
@@ -6296,6 +6299,23 @@ struct i40e_vsi *
return ret;
}

+//根据 RX/TX flags 设定 网卡 收包/发包 特征
+static int
+i40e_set_action(struct i40e_pf *pf)
+{
+ struct i40e_vsi *vsi = pf->main_vsi;
+ struct i40e_hw *hw = I40E_VSI_TO_HW(vsi);
+ struct rte_eth_dev *dev = container_of(pf, struct i40e_adapter, pf)->eth_dev;
+ struct rte_eth_txmode *txmode = &dev->data->dev_conf.txmode;
+ struct rte_eth_rxmode *rxmode = &dev->data->dev_conf.rxmode;
+ bool allow_tx_hw_pad = txmode->offloads & DEV_TX_OFFLOAD_DISABLE_APPEND_FRAME ? FALSE:TRUE;
+ bool allow_tx_hw_crc = txmode->offloads & DEV_TX_OFFLOAD_DISABLE_APPEND_CRC ? FALSE:TRUE;
+ bool allow_rx_hw_sbp = rxmode->offloads & DEV_RX_OFFLOAD_SAVE_BAD_PACKET ? TRUE:FALSE;
+ i40e_aq_set_port_parameters(hw, vsi->seid, allow_rx_hw_sbp, allow_tx_hw_pad, TRUE, NULL);
+ i40e_aq_set_mac_config(hw, I40E_FRAME_SIZE_MAX, allow_tx_hw_crc, 0, NULL);
+ return 0;
+}
+
static int
i40e_dev_rxtx_init(struct i40e_pf *pf)
{
@@ -6312,6 +6332,8 @@ struct i40e_vsi *
return err;
}

+ //根据 RX/TX flags 设定 网卡 收包/发包 特征
+ i40e_set_action(pf);
return err;
}

diff --git a/drivers/net/ixgbe/ixgbe_rxtx.c b/drivers/net/ixgbe/ixgbe_rxtx.c
index ddc7efa..a66ac58 100644
--- a/drivers/net/ixgbe/ixgbe_rxtx.c
+++ b/drivers/net/ixgbe/ixgbe_rxtx.c
@@ -2433,6 +2433,8 @@ void __attribute__((cold))
DEV_TX_OFFLOAD_TCP_CKSUM |
DEV_TX_OFFLOAD_SCTP_CKSUM |
DEV_TX_OFFLOAD_TCP_TSO |
+ DEV_TX_OFFLOAD_DISABLE_APPEND_FRAME |
+ DEV_TX_OFFLOAD_DISABLE_APPEND_CRC |
DEV_TX_OFFLOAD_MULTI_SEGS;

if (hw->mac.type == ixgbe_mac_82599EB ||
@@ -2853,6 +2855,7 @@ static void __attribute__((cold))
DEV_RX_OFFLOAD_TCP_CKSUM |
DEV_RX_OFFLOAD_KEEP_CRC |
DEV_RX_OFFLOAD_JUMBO_FRAME |
+ DEV_RX_OFFLOAD_SAVE_BAD_PACKET |
DEV_RX_OFFLOAD_SCATTER;

if (hw->mac.type == ixgbe_mac_82598EB)
@@ -4850,6 +4853,13 @@ int __attribute__((cold))
fctrl |= IXGBE_FCTRL_BAM;
fctrl |= IXGBE_FCTRL_DPF;
fctrl |= IXGBE_FCTRL_PMCF;
+
+ //如果 允许 保存 错误 报文
+ if(rx_conf->offloads & DEV_RX_OFFLOAD_SAVE_BAD_PACKET)
+ {
+ fctrl |= IXGBE_FCTRL_SBP;
+ }
+
IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);

/*
@@ -4998,6 +5008,7 @@ void __attribute__((cold))
uint32_t hlreg0;
uint32_t txctrl;
uint16_t i;
+ struct rte_eth_txmode *tx_conf = &dev->data->dev_conf.txmode;

PMD_INIT_FUNC_TRACE();
hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
@@ -5006,7 +5017,27 @@ void __attribute__((cold))
* (TSO requirement)
*/
hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
- hlreg0 |= (IXGBE_HLREG0_TXCRCEN | IXGBE_HLREG0_TXPADEN);
+
+ //如果禁用网卡 CRC 检测
+ if(tx_conf->offloads & DEV_TX_OFFLOAD_DISABLE_APPEND_CRC)
+ {
+ hlreg0 &=~IXGBE_HLREG0_TXCRCEN;
+ }
+ else
+ {
+ hlreg0 |= IXGBE_HLREG0_TXCRCEN;
+ }
+
+ //如果禁用网卡对齐
+ if(tx_conf->offloads & DEV_TX_OFFLOAD_DISABLE_APPEND_FRAME)
+ {
+ hlreg0 &= ~IXGBE_HLREG0_TXPADEN;
+ }
+ else
+ {
+ hlreg0 |= IXGBE_HLREG0_TXPADEN;
+ }
+
IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);

/* Setup the Base and Length of the Tx Descriptor Rings */
diff --git a/examples/tx_only/Makefile b/examples/tx_only/Makefile
new file mode 100644
index 0000000..4c0202d
--- /dev/null
+++ b/examples/tx_only/Makefile
@@ -0,0 +1,55 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2010-2014 Intel Corporation
+
+# binary name
+APP = tx_only
+
+# all source are stored in SRCS-y
+SRCS-y := main.c
+
+# Build using pkg-config variables if possible
+$(shell pkg-config --exists libdpdk)
+ifeq ($(.SHELLSTATUS),0)
+
+all: shared
+.PHONY: shared static
+shared: build/$(APP)-shared
+ ln -sf $(APP)-shared build/$(APP)
+static: build/$(APP)-static
+ ln -sf $(APP)-static build/$(APP)
+
+PC_FILE := $(shell pkg-config --path libdpdk)
+CFLAGS += -O3 $(shell pkg-config --cflags libdpdk)
+LDFLAGS_SHARED = $(shell pkg-config --libs libdpdk)
+LDFLAGS_STATIC = -Wl,-Bstatic $(shell pkg-config --static --libs libdpdk)
+
+build/$(APP)-shared: $(SRCS-y) Makefile $(PC_FILE) | build
+ $(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_SHARED)
+
+build/$(APP)-static: $(SRCS-y) Makefile $(PC_FILE) | build
+ $(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_STATIC)
+
+build:
+ @mkdir -p $@
+
+.PHONY: clean
+clean:
+ rm -f build/$(APP) build/$(APP)-static build/$(APP)-shared
+ rmdir --ignore-fail-on-non-empty build
+
+else # Build using legacy build system
+
+ifeq ($(RTE_SDK),)
+$(error "Please define RTE_SDK environment variable")
+endif
+
+# Default target, can be overridden by command line or environment
+RTE_TARGET ?= x86_64-native-linuxapp-gcc
+
+include $(RTE_SDK)/mk/rte.vars.mk
+
+CFLAGS += -O3
+CFLAGS += $(WERROR_FLAGS)
+
+include $(RTE_SDK)/mk/rte.extapp.mk
+endif
diff --git a/examples/tx_only/main.c b/examples/tx_only/main.c
new file mode 100644
index 0000000..0ddd44b
--- /dev/null
+++ b/examples/tx_only/main.c
@@ -0,0 +1,1007 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2010-2016 Intel Corporation
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdint.h>
+#include <inttypes.h>
+#include <sys/types.h>
+#include <sys/queue.h>
+#include <netinet/in.h>
+#include <setjmp.h>
+#include <stdarg.h>
+#include <ctype.h>
+#include <errno.h>
+#include <getopt.h>
+#include <signal.h>
+#include <stdbool.h>
+
+#include <rte_common.h>
+#include <rte_log.h>
+#include <rte_malloc.h>
+#include <rte_memory.h>
+#include <rte_memcpy.h>
+#include <rte_eal.h>
+#include <rte_launch.h>
+#include <rte_atomic.h>
+#include <rte_cycles.h>
+#include <rte_prefetch.h>
+#include <rte_lcore.h>
+#include <rte_per_lcore.h>
+#include <rte_branch_prediction.h>
+#include <rte_interrupts.h>
+#include <rte_random.h>
+#include <rte_debug.h>
+#include <rte_ether.h>
+#include <rte_ethdev.h>
+#include <rte_mempool.h>
+#include <rte_mbuf.h>
+
+static volatile bool force_quit;
+
+/* MAC updating enabled by default */
+static int mac_updating = 1;
+static int enable_pkt_gen = 0;
+static int rx_keep_crc = 0;
+static int rx_enable_forward = 0;
+static int rx_keep_sbp = 0;
+static int tx_disable_pad_crc = 0;
+static int tx_disable_pad_frame = 0;
+
+#define RTE_LOGTYPE_L2FWD RTE_LOGTYPE_USER1
+
+#define MAX_PKT_BURST 32
+#define BURST_TX_DRAIN_US 100 /* TX drain every ~100us */
+#define MEMPOOL_CACHE_SIZE 256
+
+/*
+ * Configurable number of RX/TX ring descriptors
+ */
+#define RTE_TEST_RX_DESC_DEFAULT 1024
+#define RTE_TEST_TX_DESC_DEFAULT 1024
+static uint16_t nb_rxd = RTE_TEST_RX_DESC_DEFAULT;
+static uint16_t nb_txd = RTE_TEST_TX_DESC_DEFAULT;
+
+/* ethernet addresses of ports */
+static struct ether_addr l2fwd_ports_eth_addr[RTE_MAX_ETHPORTS];
+
+/* mask of enabled ports */
+static uint32_t l2fwd_enabled_port_mask = 0;
+
+/* list of enabled ports */
+static uint32_t l2fwd_dst_ports[RTE_MAX_ETHPORTS];
+
+static unsigned int l2fwd_rx_queue_per_lcore = 1;
+
+#define MAX_RX_QUEUE_PER_LCORE 16
+#define MAX_TX_QUEUE_PER_PORT 16
+struct lcore_queue_conf {
+ unsigned n_rx_port;
+ unsigned rx_port_list[MAX_RX_QUEUE_PER_LCORE];
+} __rte_cache_aligned;
+struct lcore_queue_conf lcore_queue_conf[RTE_MAX_LCORE];
+
+static struct rte_eth_dev_tx_buffer *tx_buffer[RTE_MAX_ETHPORTS];
+
+static struct rte_eth_conf port_conf = {
+ .rxmode = {
+ .split_hdr_size = 0,
+ },
+ .txmode = {
+ .mq_mode = ETH_MQ_TX_NONE,
+ },
+};
+
+struct rte_mempool * l2fwd_pktmbuf_pool = NULL;
+
+
+/* Per-port statistics struct */
+struct l2fwd_port_statistics {
+ uint64_t tx;
+ uint64_t rx;
+ uint64_t dropped;
+
+ uint64_t ipackets; /**< Total number of successfully received packets. */
+ uint64_t opackets; /**< Total number of successfully transmitted packets.*/
+ uint64_t ibytes; /**< Total number of successfully received bytes. */
+ uint64_t obytes; /**< Total number of successfully transmitted bytes. */
+ uint64_t imissed; /**< Total of RX packets dropped by the HW, */
+ uint64_t ierrors; /**< Total number of erroneous received packets. */
+ uint64_t oerrors; /**< Total number of failed transmitted packets. */
+ uint64_t rx_nombuf; /**< Total number of RX mbuf allocation failures. */
+} __rte_cache_aligned;
+struct l2fwd_port_statistics port_statistics[RTE_MAX_ETHPORTS];
+struct l2fwd_port_statistics last_statistics[RTE_MAX_ETHPORTS];
+
+#define MAX_TIMER_PERIOD 86400 /* 1 day max */
+/* A tsc-based timer responsible for triggering statistics printout */
+static uint64_t timer_period = 10; /* default period is 10 seconds */
+
+
+
+/* Print out statistics on packets dropped */
+static void
+print_stats(void)
+{
+ uint64_t total_packets_dropped, total_packets_tx, total_packets_rx;
+ unsigned portid;
+
+ total_packets_dropped = 0;
+ total_packets_tx = 0;
+ total_packets_rx = 0;
+
+ const char clr[] = { 27, '[', '2', 'J', '\0' };
+ const char topLeft[] = { 27, '[', '1', ';', '1', 'H','\0' };
+
+ /* Clear screen and move to top left */
+ printf("%s%s", clr, topLeft);
+
+ printf("\nPort statistics ====================================");
+
+ for (portid = 0; portid < RTE_MAX_ETHPORTS; portid++) {
+ /* skip disabled ports */
+ if ((l2fwd_enabled_port_mask & (1 << portid)) == 0)
+ continue;
+
+ struct rte_eth_stats stat_info;
+ rte_eth_stats_get(portid, &stat_info);
+
+ uint16_t mtu = 0;
+ rte_eth_dev_get_mtu(portid, &mtu);
+
+ printf("\nStatistics for port %u ------------------------------"
+ "\nPackets sent: %24"PRIu64
+ "\nPackets received: %20"PRIu64
+ "\nSpeed PPS sent: %22"PRIu64
+ "\nSpeed PPS received: %18"PRIu64
+ "\nPackets dropped: %21"PRIu64,
+ portid,
+ port_statistics[portid].tx,
+ port_statistics[portid].rx,
+ port_statistics[portid].tx - last_statistics[portid].tx,
+ port_statistics[portid].rx - last_statistics[portid].rx,
+ port_statistics[portid].dropped);
+
+ printf("\nDevice MTU: %26"PRIu16, mtu);
+ printf("\nDevice ipackets: %21"PRIu64, stat_info.ipackets);
+ printf("\nDevice opackets: %21"PRIu64, stat_info.opackets);
+ printf("\nDevice ibytes: %23"PRIu64, stat_info.ibytes);
+ printf("\nDevice obytes: %23"PRIu64, stat_info.obytes);
+ printf("\nDevice imissed: %22"PRIu64, stat_info.imissed);
+ printf("\nDevice ierrors: %22"PRIu64, stat_info.ierrors);
+ printf("\nDevice oerrors: %22"PRIu64, stat_info.oerrors);
+ printf("\nDevice rx_nombuf: %20"PRIu64, stat_info.rx_nombuf);
+
+ last_statistics[portid].tx = port_statistics[portid].tx;
+ last_statistics[portid].rx = port_statistics[portid].rx;
+
+ total_packets_dropped += port_statistics[portid].dropped;
+ total_packets_tx += port_statistics[portid].tx;
+ total_packets_rx += port_statistics[portid].rx;
+ }
+ printf("\nAggregate statistics ==============================="
+ "\nTotal packets sent: %18"PRIu64
+ "\nTotal packets received: %14"PRIu64
+ "\nTotal packets dropped: %15"PRIu64,
+ total_packets_tx,
+ total_packets_rx,
+ total_packets_dropped);
+ printf("\n====================================================\n");
+}
+
+static void
+l2fwd_mac_updating(struct rte_mbuf *m, unsigned dest_portid)
+{
+ struct ether_hdr *eth;
+ void *tmp;
+
+ eth = rte_pktmbuf_mtod(m, struct ether_hdr *);
+
+ /* 02:00:00:00:00:xx */
+ tmp = &eth->d_addr.addr_bytes[0];
+ *((uint64_t *)tmp) = 0x000000000002 + ((uint64_t)dest_portid << 40);
+
+ /* src addr */
+ ether_addr_copy(&l2fwd_ports_eth_addr[dest_portid], &eth->s_addr);
+}
+
+static void
+l2fwd_simple_forward(struct rte_mbuf *m, unsigned portid)
+{
+ unsigned dst_port;
+ int sent;
+ struct rte_eth_dev_tx_buffer *buffer;
+
+ dst_port = l2fwd_dst_ports[portid];
+
+ if (mac_updating)
+ l2fwd_mac_updating(m, dst_port);
+
+ buffer = tx_buffer[dst_port];
+ sent = rte_eth_tx_buffer(dst_port, 0, buffer, m);
+ if (sent)
+ port_statistics[dst_port].tx += sent;
+}
+
+char packet_http_get[] = {
+ 0x30, 0xfc, 0x68, 0xff, 0x70, 0xfb, 0x02, 0xa9,
+ 0x1c, 0x7d, 0xea, 0x54, 0x08, 0x00, 0x45, 0x00,
+ 0x05, 0x25, 0xe5, 0xdd, 0x40, 0x00, 0x80, 0x06,
+ 0x80, 0x99, 0xac, 0x10, 0x14, 0x3a, 0x7a, 0xe2,
+ 0x54, 0x2f, 0x15, 0xba, 0x00, 0x50, 0x7e, 0xf8,
+ 0x4b, 0xfc, 0x92, 0xd3, 0x8d, 0x1d, 0x50, 0x18,
+ 0x01, 0x00, 0xaf, 0x4d, 0x00, 0x00, 0x47, 0x45,
+ 0x54, 0x20, 0x2f, 0x63, 0x75, 0x73, 0x74, 0x6f,
+ 0x6d, 0x2f, 0x37, 0x32, 0x31, 0x31, 0x30, 0x33,
+ 0x34, 0x38, 0x2f, 0x6d, 0x6f, 0x62, 0x69, 0x6c,
+ 0x65, 0x5f, 0x69, 0x63, 0x6f, 0x6e, 0x5f, 0x37,
+ 0x32, 0x31, 0x31, 0x30, 0x33, 0x34, 0x38, 0x5f,
+ 0x32, 0x2e, 0x6a, 0x73, 0x3f, 0x76, 0x3d, 0x31,
+ 0x35, 0x30, 0x32, 0x31, 0x37, 0x39, 0x36, 0x30,
+ 0x31, 0x20, 0x48, 0x54, 0x54, 0x50, 0x2f, 0x31,
+ 0x2e, 0x31, 0x0d, 0x0a, 0x48, 0x6f, 0x73, 0x74,
+ 0x3a, 0x20, 0x77, 0x77, 0x77, 0x31, 0x30, 0x63,
+ 0x31, 0x2e, 0x35, 0x33, 0x6b, 0x66, 0x2e, 0x63,
+ 0x6f, 0x6d, 0x0d, 0x0a, 0x43, 0x6f, 0x6e, 0x6e,
+ 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x3a, 0x20,
+ 0x6b, 0x65, 0x65, 0x70, 0x2d, 0x61, 0x6c, 0x69,
+ 0x76, 0x65, 0x0d, 0x0a, 0x55, 0x73, 0x65, 0x72,
+ 0x2d, 0x41, 0x67, 0x65, 0x6e, 0x74, 0x3a, 0x20,
+ 0x4d, 0x6f, 0x7a, 0x69, 0x6c, 0x6c, 0x61, 0x2f,
+ 0x35, 0x2e, 0x30, 0x20, 0x28, 0x57, 0x69, 0x6e,
+ 0x64, 0x6f, 0x77, 0x73, 0x20, 0x4e, 0x54, 0x20,
+ 0x31, 0x30, 0x2e, 0x30, 0x3b, 0x20, 0x57, 0x69,
+ 0x6e, 0x36, 0x34, 0x3b, 0x20, 0x78, 0x36, 0x34,
+ 0x29, 0x20, 0x41, 0x70, 0x70, 0x6c, 0x65, 0x57,
+ 0x65, 0x62, 0x4b, 0x69, 0x74, 0x2f, 0x35, 0x33,
+ 0x37, 0x2e, 0x33, 0x36, 0x20, 0x28, 0x4b, 0x48,
+ 0x54, 0x4d, 0x4c, 0x2c, 0x20, 0x6c, 0x69, 0x6b,
+ 0x65, 0x20, 0x47, 0x65, 0x63, 0x6b, 0x6f, 0x29,
+ 0x20, 0x43, 0x68, 0x72, 0x6f, 0x6d, 0x65, 0x2f,
+ 0x38, 0x31, 0x2e, 0x30, 0x2e, 0x34, 0x30, 0x34,
+ 0x34, 0x2e, 0x31, 0x33, 0x38, 0x20, 0x53, 0x61,
+ 0x66, 0x61, 0x72, 0x69, 0x2f, 0x35, 0x33, 0x37,
+ 0x2e, 0x33, 0x36, 0x0d, 0x0a, 0x41, 0x63, 0x63,
+ 0x65, 0x70, 0x74, 0x3a, 0x20, 0x2a, 0x2f, 0x2a,
+ 0x0d, 0x0a, 0x52, 0x65, 0x66, 0x65, 0x72, 0x65,
+ 0x72, 0x3a, 0x20, 0x68, 0x74, 0x74, 0x70, 0x3a,
+ 0x2f, 0x2f, 0x77, 0x77, 0x77, 0x2e, 0x69, 0x62,
+ 0x65, 0x69, 0x66, 0x65, 0x6e, 0x67, 0x2e, 0x63,
+ 0x6f, 0x6d, 0x2f, 0x0d, 0x0a, 0x41, 0x63, 0x63,
+ 0x65, 0x70, 0x74, 0x2d, 0x45, 0x6e, 0x63, 0x6f,
+ 0x64, 0x69, 0x6e, 0x67, 0x3a, 0x20, 0x67, 0x7a,
+ 0x69, 0x70, 0x2c, 0x20, 0x64, 0x65, 0x66, 0x6c,
+ 0x61, 0x74, 0x65, 0x0d, 0x0a, 0x41, 0x63, 0x63,
+ 0x65, 0x70, 0x74, 0x2d, 0x4c, 0x61, 0x6e, 0x67,
+ 0x75, 0x61, 0x67, 0x65, 0x3a, 0x20, 0x7a, 0x68,
+ 0x2d, 0x43, 0x4e, 0x2c, 0x7a, 0x68, 0x3b, 0x71,
+ 0x3d, 0x30, 0x2e, 0x39, 0x2c, 0x65, 0x6e, 0x3b,
+ 0x71, 0x3d, 0x30, 0x2e, 0x38, 0x0d, 0x0a, 0x43,
+ 0x6f, 0x6f, 0x6b, 0x69, 0x65, 0x3a, 0x20, 0x67,
+ 0x75, 0x65, 0x73, 0x74, 0x5f, 0x69, 0x64, 0x3d,
+ 0x31, 0x31, 0x36, 0x35, 0x38, 0x31, 0x33, 0x34,
+ 0x30, 0x37, 0x36, 0x30, 0x30, 0x35, 0x3b, 0x20,
+ 0x6c, 0x61, 0x6e, 0x64, 0x5f, 0x70, 0x61, 0x67,
+ 0x65, 0x5f, 0x37, 0x32, 0x31, 0x34, 0x35, 0x34,
+ 0x32, 0x33, 0x3d, 0x68, 0x74, 0x74, 0x70, 0x25,
+ 0x33, 0x41, 0x25, 0x32, 0x46, 0x25, 0x32, 0x46,
+ 0x77, 0x77, 0x77, 0x2e, 0x6d, 0x61, 0x67, 0x65,
+ 0x64, 0x75, 0x2e, 0x63, 0x6f, 0x6d, 0x25, 0x32,
+ 0x46, 0x3b, 0x20, 0x35, 0x33, 0x63, 0x74, 0x5f,
+ 0x31, 0x31, 0x36, 0x35, 0x38, 0x31, 0x33, 0x34,
+ 0x30, 0x37, 0x36, 0x30, 0x30, 0x35, 0x3d, 0x31,
+ 0x35, 0x38, 0x39, 0x33, 0x36, 0x30, 0x39, 0x35,
+ 0x34, 0x5f, 0x31, 0x3b, 0x20, 0x74, 0x61, 0x6c,
+ 0x6b, 0x74, 0x69, 0x74, 0x6c, 0x65, 0x5f, 0x37,
+ 0x32, 0x31, 0x34, 0x35, 0x34, 0x32, 0x33, 0x3d,
+ 0x25, 0x45, 0x39, 0x25, 0x41, 0x39, 0x25, 0x41,
+ 0x43, 0x25, 0x45, 0x35, 0x25, 0x39, 0x33, 0x25,
+ 0x41, 0x35, 0x25, 0x45, 0x36, 0x25, 0x39, 0x35,
+ 0x25, 0x39, 0x39, 0x25, 0x45, 0x38, 0x25, 0x38,
+ 0x32, 0x25, 0x42, 0x32, 0x25, 0x45, 0x35, 0x25,
+ 0x41, 0x45, 0x25, 0x39, 0x38, 0x25, 0x45, 0x37,
+ 0x25, 0x42, 0x44, 0x25, 0x39, 0x31, 0x2d, 0x25,
+ 0x45, 0x34, 0x25, 0x42, 0x38, 0x25, 0x39, 0x33,
+ 0x25, 0x45, 0x34, 0x25, 0x42, 0x38, 0x25, 0x39,
+ 0x41, 0x4c, 0x69, 0x6e, 0x75, 0x78, 0x25, 0x45,
+ 0x35, 0x25, 0x39, 0x46, 0x25, 0x42, 0x39, 0x25,
+ 0x45, 0x38, 0x25, 0x41, 0x45, 0x25, 0x41, 0x44,
+ 0x25, 0x45, 0x37, 0x25, 0x38, 0x46, 0x25, 0x41,
+ 0x44, 0x25, 0x32, 0x43, 0x50, 0x79, 0x74, 0x68,
+ 0x6f, 0x6e, 0x25, 0x45, 0x35, 0x25, 0x39, 0x46,
+ 0x25, 0x42, 0x39, 0x25, 0x45, 0x38, 0x25, 0x41,
+ 0x45, 0x25, 0x41, 0x44, 0x25, 0x45, 0x36, 0x25,
+ 0x39, 0x43, 0x25, 0x42, 0x41, 0x25, 0x45, 0x36,
+ 0x25, 0x39, 0x45, 0x25, 0x38, 0x34, 0x3b, 0x20,
+ 0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x65, 0x72,
+ 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65,
+ 0x5f, 0x6c, 0x61, 0x6e, 0x67, 0x75, 0x61, 0x67,
+ 0x65, 0x3d, 0x63, 0x6e, 0x3b, 0x20, 0x69, 0x73,
+ 0x5f, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x5f, 0x3d,
+ 0x30, 0x3b, 0x20, 0x6c, 0x61, 0x6e, 0x64, 0x5f,
+ 0x70, 0x61, 0x67, 0x65, 0x5f, 0x37, 0x32, 0x31,
+ 0x39, 0x36, 0x35, 0x35, 0x30, 0x3d, 0x68, 0x74,
+ 0x74, 0x70, 0x73, 0x25, 0x33, 0x41, 0x25, 0x32,
+ 0x46, 0x25, 0x32, 0x46, 0x77, 0x77, 0x77, 0x2e,
+ 0x71, 0x69, 0x64, 0x69, 0x61, 0x6e, 0x6c, 0x61,
+ 0x2e, 0x63, 0x6f, 0x6d, 0x25, 0x32, 0x46, 0x3b,
+ 0x20, 0x74, 0x61, 0x6c, 0x6b, 0x74, 0x69, 0x74,
+ 0x6c, 0x65, 0x5f, 0x37, 0x32, 0x31, 0x39, 0x36,
+ 0x35, 0x35, 0x30, 0x3d, 0x25, 0x45, 0x38, 0x25,
+ 0x42, 0x35, 0x25, 0x42, 0x37, 0x25, 0x45, 0x37,
+ 0x25, 0x38, 0x32, 0x25, 0x42, 0x39, 0x25, 0x45,
+ 0x35, 0x25, 0x41, 0x44, 0x25, 0x41, 0x36, 0x25,
+ 0x45, 0x39, 0x25, 0x39, 0x39, 0x25, 0x41, 0x32,
+ 0x2d, 0x25, 0x45, 0x34, 0x25, 0x42, 0x41, 0x25,
+ 0x41, 0x37, 0x25, 0x45, 0x35, 0x25, 0x39, 0x33,
+ 0x25, 0x38, 0x31, 0x25, 0x45, 0x37, 0x25, 0x42,
+ 0x42, 0x25, 0x38, 0x46, 0x25, 0x45, 0x37, 0x25,
+ 0x39, 0x30, 0x25, 0x38, 0x36, 0x25, 0x45, 0x35,
+ 0x25, 0x39, 0x46, 0x25, 0x42, 0x39, 0x25, 0x45,
+ 0x38, 0x25, 0x41, 0x45, 0x25, 0x41, 0x44, 0x2b,
+ 0x25, 0x37, 0x43, 0x2b, 0x25, 0x45, 0x34, 0x25,
+ 0x42, 0x41, 0x25, 0x41, 0x37, 0x25, 0x45, 0x35,
+ 0x25, 0x39, 0x33, 0x25, 0x38, 0x31, 0x25, 0x45,
+ 0x37, 0x25, 0x42, 0x42, 0x25, 0x38, 0x46, 0x25,
+ 0x45, 0x37, 0x25, 0x39, 0x30, 0x25, 0x38, 0x36,
+ 0x25, 0x45, 0x35, 0x25, 0x39, 0x46, 0x25, 0x42,
+ 0x39, 0x25, 0x45, 0x38, 0x25, 0x41, 0x45, 0x25,
+ 0x41, 0x44, 0x25, 0x45, 0x38, 0x25, 0x41, 0x46,
+ 0x25, 0x42, 0x45, 0x25, 0x45, 0x37, 0x25, 0x41,
+ 0x38, 0x25, 0x38, 0x42, 0x2b, 0x25, 0x37, 0x43,
+ 0x2b, 0x25, 0x45, 0x38, 0x25, 0x38, 0x37, 0x25,
+ 0x42, 0x34, 0x25, 0x45, 0x35, 0x25, 0x38, 0x41,
+ 0x25, 0x39, 0x42, 0x25, 0x45, 0x34, 0x25, 0x42,
+ 0x41, 0x25, 0x38, 0x45, 0x25, 0x45, 0x34, 0x25,
+ 0x42, 0x38, 0x25, 0x42, 0x41, 0x49, 0x54, 0x25,
+ 0x45, 0x34, 0x25, 0x42, 0x42, 0x25, 0x38, 0x45,
+ 0x25, 0x45, 0x34, 0x25, 0x42, 0x38, 0x25, 0x39,
+ 0x41, 0x25, 0x45, 0x38, 0x25, 0x38, 0x30, 0x25,
+ 0x38, 0x35, 0x25, 0x45, 0x36, 0x25, 0x38, 0x46,
+ 0x25, 0x39, 0x30, 0x25, 0x45, 0x34, 0x25, 0x42,
+ 0x45, 0x25, 0x39, 0x42, 0x25, 0x45, 0x34, 0x25,
+ 0x42, 0x38, 0x25, 0x39, 0x33, 0x25, 0x45, 0x34,
+ 0x25, 0x42, 0x38, 0x25, 0x39, 0x41, 0x25, 0x45,
+ 0x33, 0x25, 0x38, 0x30, 0x25, 0x38, 0x31, 0x25,
+ 0x45, 0x37, 0x25, 0x42, 0x33, 0x25, 0x42, 0x42,
+ 0x25, 0x45, 0x37, 0x25, 0x42, 0x42, 0x25, 0x39,
+ 0x46, 0x25, 0x45, 0x37, 0x25, 0x39, 0x41, 0x25,
+ 0x38, 0x34, 0x25, 0x45, 0x34, 0x25, 0x42, 0x41,
+ 0x25, 0x41, 0x37, 0x25, 0x45, 0x35, 0x25, 0x39,
+ 0x33, 0x25, 0x38, 0x31, 0x25, 0x45, 0x37, 0x25,
+ 0x42, 0x42, 0x25, 0x38, 0x46, 0x25, 0x45, 0x37,
+ 0x25, 0x39, 0x30, 0x25, 0x38, 0x36, 0x25, 0x45,
+ 0x35, 0x25, 0x41, 0x44, 0x25, 0x41, 0x36, 0x25,
+ 0x45, 0x34, 0x25, 0x42, 0x39, 0x25, 0x41, 0x30,
+ 0x25, 0x45, 0x36, 0x25, 0x39, 0x43, 0x25, 0x38,
+ 0x44, 0x25, 0x45, 0x35, 0x25, 0x38, 0x41, 0x25,
+ 0x41, 0x31, 0x25, 0x45, 0x46, 0x25, 0x42, 0x43,
+ 0x25, 0x38, 0x43, 0x25, 0x45, 0x37, 0x25, 0x39,
+ 0x42, 0x25, 0x41, 0x45, 0x25, 0x45, 0x36, 0x25,
+ 0x41, 0x30, 0x25, 0x38, 0x37, 0x25, 0x45, 0x36,
+ 0x25, 0x38, 0x38, 0x25, 0x39, 0x30, 0x25, 0x45,
+ 0x34, 0x25, 0x42, 0x38, 0x25, 0x42, 0x41, 0x25,
+ 0x45, 0x34, 0x25, 0x42, 0x41, 0x25, 0x41, 0x37,
+ 0x25, 0x45, 0x35, 0x25, 0x39, 0x33, 0x25, 0x38,
+ 0x31, 0x25, 0x45, 0x37, 0x25, 0x42, 0x42, 0x25,
+ 0x38, 0x46, 0x25, 0x45, 0x37, 0x25, 0x39, 0x30,
+ 0x25, 0x38, 0x36, 0x25, 0x45, 0x39, 0x25, 0x42,
+ 0x42, 0x25, 0x38, 0x34, 0x25, 0x45, 0x35, 0x25,
+ 0x39, 0x46, 0x25, 0x39, 0x34, 0x25, 0x45, 0x35,
+ 0x25, 0x38, 0x36, 0x25, 0x39, 0x42, 0x25, 0x45,
+ 0x36, 0x25, 0x41, 0x30, 0x25, 0x41, 0x31, 0x0d,
+ 0x0a, 0x0d, 0x0a
+};
+
+
+/* main processing loop */
+static void
+l2fwd_main_loop(void)
+{
+ struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
+ struct rte_mbuf *m;
+ int sent;
+ unsigned lcore_id;
+ uint64_t prev_tsc, diff_tsc, cur_tsc, timer_tsc;
+ unsigned i, j, portid, nb_rx;
+ struct lcore_queue_conf *qconf;
+ const uint64_t drain_tsc = (rte_get_tsc_hz() + US_PER_S - 1) / US_PER_S *
+ BURST_TX_DRAIN_US;
+ struct rte_eth_dev_tx_buffer *buffer;
+
+ prev_tsc = 0;
+ timer_tsc = 0;
+
+ lcore_id = rte_lcore_id();
+ qconf = &lcore_queue_conf[lcore_id];
+
+ if (qconf->n_rx_port == 0) {
+ RTE_LOG(INFO, L2FWD, "lcore %u has nothing to do\n", lcore_id);
+ return;
+ }
+
+ RTE_LOG(INFO, L2FWD, "entering main loop on lcore %u\n", lcore_id);
+
+ for (i = 0; i < qconf->n_rx_port; i++) {
+
+ portid = qconf->rx_port_list[i];
+ RTE_LOG(INFO, L2FWD, " -- lcoreid=%u portid=%u\n", lcore_id,
+ portid);
+
+ }
+
+ int index = 0;
+ int new_packet = 0;
+ while (!force_quit) {
+
+ cur_tsc = rte_rdtsc();
+
+ /*
+ * TX burst queue drain
+ */
+ diff_tsc = cur_tsc - prev_tsc;
+ if (unlikely(diff_tsc > drain_tsc)) {
+
+ for (i = 0; i < qconf->n_rx_port; i++) {
+
+ portid = l2fwd_dst_ports[qconf->rx_port_list[i]];
+ buffer = tx_buffer[portid];
+
+ sent = rte_eth_tx_buffer_flush(portid, 0, buffer);
+ if (sent)
+ port_statistics[portid].tx += sent;
+
+ }
+
+ /* if timer is enabled */
+ if (timer_period > 0) {
+
+ /* advance the timer */
+ timer_tsc += diff_tsc;
+
+ /* if timer has reached its timeout */
+ if (unlikely(timer_tsc >= timer_period)) {
+
+ /* do this only on master core */
+ if (lcore_id == rte_get_master_lcore()) {
+ print_stats();
+ /* reset the timer */
+ timer_tsc = 0;
+ }
+ }
+ }
+
+ prev_tsc = cur_tsc;
+ }
+
+ /*
+ * Read packet from RX queues
+ */
+ for (i = 0; i < qconf->n_rx_port; i++) {
+
+ portid = qconf->rx_port_list[i];
+ nb_rx = rte_eth_rx_burst(portid, 0,
+ pkts_burst, MAX_PKT_BURST);
+
+ port_statistics[portid].rx += nb_rx;
+
+ for (j = 0; j < nb_rx; j++) {
+ index++;
+ m = pkts_burst[j];
+ printf("RX index=%d pkt_len=%d data_len=%d next=%p\n", index, rte_pktmbuf_pkt_len(m), rte_pktmbuf_data_len(m), m->next);
+
+ if(rx_enable_forward)
+ {
+ rte_prefetch0(rte_pktmbuf_mtod(m, void *));
+ l2fwd_simple_forward(m, portid);
+ }
+ else
+ {
+ rte_pktmbuf_free(m);
+ }
+ }
+
+ //造包
+ if(0 == nb_rx && enable_pkt_gen)
+ {
+ struct rte_mbuf *a = rte_pktmbuf_alloc(l2fwd_pktmbuf_pool);
+ if (a)
+ {
+ new_packet++;
+ char *p = rte_pktmbuf_mtod(a, char *);
+ memcpy(p, packet_http_get, sizeof(packet_http_get));
+ rte_pktmbuf_pkt_len(a) = sizeof(packet_http_get);
+ rte_pktmbuf_data_len(a) = sizeof(packet_http_get);
+ printf("造包 new_packet=%d len=%d\n", new_packet, rte_pktmbuf_pkt_len(a));
+ l2fwd_simple_forward(a, portid);
+ }
+ }
+ }
+ }
+}
+
+static int
+l2fwd_launch_one_lcore(__attribute__((unused)) void *dummy)
+{
+ l2fwd_main_loop();
+ return 0;
+}
+
+/* display usage */
+static void
+l2fwd_usage(const char *prgname)
+{
+ printf("%s [EAL options] -- -p PORTMASK [-q NQ]\n"
+ " -p PORTMASK: hexadecimal bitmask of ports to configure\n"
+ " -q NQ: number of queue (=ports) per lcore (default is 1)\n"
+ " -T PERIOD: statistics will be refreshed each PERIOD seconds (0 to disable, 10 default, 86400 maximum)\n"
+ " --rx_enable_forward: 允许将收到的包 转发\n"
+ " --enable_pkt_gen: 允许造包 并 发送\n"
+ " --rx_keep_crc: 网卡接收时保留CRC\n"
+ " --rx_keep_sbp: 网卡接收时保留CRC校验错误的报文\n"
+ " --tx_disable_pad_crc: 网卡发送时不要追加 CRC\n"
+ " --tx_disable_pad_frame:网卡发送小包时, 不要填充帧\n"
+ " --[no-]mac-updating: Enable or disable MAC addresses updating (enabled by default)\n"
+ " When enabled:\n"
+ " - The source MAC address is replaced by the TX port MAC address\n"
+ " - The destination MAC address is replaced by 02:00:00:00:00:TX_PORT_ID\n",
+ prgname);
+}
+
+static int
+l2fwd_parse_portmask(const char *portmask)
+{
+ char *end = NULL;
+ unsigned long pm;
+
+ /* parse hexadecimal string */
+ pm = strtoul(portmask, &end, 16);
+ if ((portmask[0] == '\0') || (end == NULL) || (*end != '\0'))
+ return -1;
+
+ if (pm == 0)
+ return -1;
+
+ return pm;
+}
+
+static unsigned int
+l2fwd_parse_nqueue(const char *q_arg)
+{
+ char *end = NULL;
+ unsigned long n;
+
+ /* parse hexadecimal string */
+ n = strtoul(q_arg, &end, 10);
+ if ((q_arg[0] == '\0') || (end == NULL) || (*end != '\0'))
+ return 0;
+ if (n == 0)
+ return 0;
+ if (n >= MAX_RX_QUEUE_PER_LCORE)
+ return 0;
+
+ return n;
+}
+
+static int
+l2fwd_parse_timer_period(const char *q_arg)
+{
+ char *end = NULL;
+ int n;
+
+ /* parse number string */
+ n = strtol(q_arg, &end, 10);
+ if ((q_arg[0] == '\0') || (end == NULL) || (*end != '\0'))
+ return -1;
+ if (n >= MAX_TIMER_PERIOD)
+ return -1;
+
+ return n;
+}
+
+static const char short_options[] =
+ "p:" /* portmask */
+ "q:" /* number of queues */
+ "T:" /* timer period */
+ ;
+
+#define CMD_LINE_OPT_MAC_UPDATING "mac-updating"
+#define CMD_LINE_OPT_NO_MAC_UPDATING "no-mac-updating"
+
+enum {
+ /* long options mapped to a short option */
+
+ /* first long only option value must be >= 256, so that we won't
+ * conflict with short options */
+ CMD_LINE_OPT_MIN_NUM = 256,
+};
+
+static const struct option lgopts[] = {
+ { CMD_LINE_OPT_MAC_UPDATING, no_argument, &mac_updating, 1},
+ { CMD_LINE_OPT_NO_MAC_UPDATING, no_argument, &mac_updating, 0},
+ { "enable_pkt_gen", no_argument, &enable_pkt_gen, 1},
+ { "rx_enable_forward", no_argument, &rx_enable_forward, 1},
+ { "rx_keep_crc", no_argument, &rx_keep_crc, 1},
+ { "rx_keep_sbp", no_argument, &rx_keep_sbp, 1},
+ { "tx_disable_pad_crc", no_argument, &tx_disable_pad_crc, 1},
+ { "tx_disable_pad_frame", no_argument, &tx_disable_pad_frame, 1},
+ {NULL, 0, 0, 0}
+};
+
+/* Parse the argument given in the command line of the application */
+static int
+l2fwd_parse_args(int argc, char **argv)
+{
+ int opt, ret, timer_secs;
+ char **argvopt;
+ int option_index;
+ char *prgname = argv[0];
+
+ argvopt = argv;
+
+ while ((opt = getopt_long(argc, argvopt, short_options,
+ lgopts, &option_index)) != EOF) {
+
+ switch (opt) {
+ /* portmask */
+ case 'p':
+ l2fwd_enabled_port_mask = l2fwd_parse_portmask(optarg);
+ if (l2fwd_enabled_port_mask == 0) {
+ printf("invalid portmask\n");
+ l2fwd_usage(prgname);
+ return -1;
+ }
+ break;
+
+ /* nqueue */
+ case 'q':
+ l2fwd_rx_queue_per_lcore = l2fwd_parse_nqueue(optarg);
+ if (l2fwd_rx_queue_per_lcore == 0) {
+ printf("invalid queue number\n");
+ l2fwd_usage(prgname);
+ return -1;
+ }
+ break;
+
+ /* timer period */
+ case 'T':
+ timer_secs = l2fwd_parse_timer_period(optarg);
+ if (timer_secs < 0) {
+ printf("invalid timer period\n");
+ l2fwd_usage(prgname);
+ return -1;
+ }
+ timer_period = timer_secs;
+ break;
+
+ /* long options */
+ case 0:
+ break;
+
+ default:
+ l2fwd_usage(prgname);
+ return -1;
+ }
+ }
+
+ if (optind >= 0)
+ argv[optind-1] = prgname;
+
+ ret = optind-1;
+ optind = 1; /* reset getopt lib */
+ return ret;
+}
+
+/* Check the link status of all ports in up to 9s, and print them finally */
+static void
+check_all_ports_link_status(uint32_t port_mask)
+{
+#define CHECK_INTERVAL 100 /* 100ms */
+#define MAX_CHECK_TIME 90 /* 9s (90 * 100ms) in total */
+ uint16_t portid;
+ uint8_t count, all_ports_up, print_flag = 0;
+ struct rte_eth_link link;
+
+ printf("\nChecking link status");
+ fflush(stdout);
+ for (count = 0; count <= MAX_CHECK_TIME; count++) {
+ if (force_quit)
+ return;
+ all_ports_up = 1;
+ RTE_ETH_FOREACH_DEV(portid) {
+ if (force_quit)
+ return;
+ if ((port_mask & (1 << portid)) == 0)
+ continue;
+ memset(&link, 0, sizeof(link));
+ rte_eth_link_get_nowait(portid, &link);
+ /* print link status if flag set */
+ if (print_flag == 1) {
+ if (link.link_status)
+ printf(
+ "Port%d Link Up. Speed %u Mbps - %s\n",
+ portid, link.link_speed,
+ (link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
+ ("full-duplex") : ("half-duplex\n"));
+ else
+ printf("Port %d Link Down\n", portid);
+ continue;
+ }
+ /* clear all_ports_up flag if any link down */
+ if (link.link_status == ETH_LINK_DOWN) {
+ all_ports_up = 0;
+ break;
+ }
+ }
+ /* after finally printing all link status, get out */
+ if (print_flag == 1)
+ break;
+
+ if (all_ports_up == 0) {
+ printf(".");
+ fflush(stdout);
+ rte_delay_ms(CHECK_INTERVAL);
+ }
+
+ /* set the print_flag if all ports up or timeout */
+ if (all_ports_up == 1 || count == (MAX_CHECK_TIME - 1)) {
+ print_flag = 1;
+ printf("done\n");
+ }
+ }
+}
+
+static void
+signal_handler(int signum)
+{
+ if (signum == SIGINT || signum == SIGTERM) {
+ printf("\n\nSignal %d received, preparing to exit...\n",
+ signum);
+ force_quit = true;
+ }
+}
+
+int
+main(int argc, char **argv)
+{
+ struct lcore_queue_conf *qconf;
+ int ret;
+ uint16_t nb_ports;
+ uint16_t nb_ports_available = 0;
+ uint16_t portid, last_port;
+ unsigned lcore_id, rx_lcore_id;
+ unsigned nb_ports_in_mask = 0;
+ unsigned int nb_lcores = 0;
+ unsigned int nb_mbufs;
+
+ /* init EAL */
+ ret = rte_eal_init(argc, argv);
+ if (ret < 0)
+ rte_exit(EXIT_FAILURE, "Invalid EAL arguments\n");
+ argc -= ret;
+ argv += ret;
+
+ force_quit = false;
+ signal(SIGINT, signal_handler);
+ signal(SIGTERM, signal_handler);
+
+ /* parse application arguments (after the EAL ones) */
+ ret = l2fwd_parse_args(argc, argv);
+ if (ret < 0)
+ rte_exit(EXIT_FAILURE, "Invalid L2FWD arguments\n");
+
+ printf("MAC updating %s\n", mac_updating ? "enabled" : "disabled");
+
+ /* convert to number of cycles */
+ timer_period *= rte_get_timer_hz();
+
+ nb_ports = rte_eth_dev_count_avail();
+ if (nb_ports == 0)
+ rte_exit(EXIT_FAILURE, "No Ethernet ports - bye\n");
+
+ /* check port mask to possible port mask */
+ if (l2fwd_enabled_port_mask & ~((1 << nb_ports) - 1))
+ rte_exit(EXIT_FAILURE, "Invalid portmask; possible (0x%x)\n",
+ (1 << nb_ports) - 1);
+
+ /* reset l2fwd_dst_ports */
+ for (portid = 0; portid < RTE_MAX_ETHPORTS; portid++)
+ l2fwd_dst_ports[portid] = 0;
+ last_port = 0;
+
+ /*
+ * Each logical core is assigned a dedicated TX queue on each port.
+ */
+ RTE_ETH_FOREACH_DEV(portid) {
+ /* skip ports that are not enabled */
+ if ((l2fwd_enabled_port_mask & (1 << portid)) == 0)
+ continue;
+
+ if (nb_ports_in_mask % 2) {
+ l2fwd_dst_ports[portid] = last_port;
+ l2fwd_dst_ports[last_port] = portid;
+ }
+ else
+ last_port = portid;
+
+ nb_ports_in_mask++;
+ }
+ if (nb_ports_in_mask % 2) {
+ printf("Notice: odd number of ports in portmask.\n");
+ l2fwd_dst_ports[last_port] = last_port;
+ }
+
+ rx_lcore_id = 0;
+ qconf = NULL;
+
+ /* Initialize the port/queue configuration of each logical core */
+ RTE_ETH_FOREACH_DEV(portid) {
+ /* skip ports that are not enabled */
+ if ((l2fwd_enabled_port_mask & (1 << portid)) == 0)
+ continue;
+
+ /* get the lcore_id for this port */
+ while (rte_lcore_is_enabled(rx_lcore_id) == 0 ||
+ lcore_queue_conf[rx_lcore_id].n_rx_port ==
+ l2fwd_rx_queue_per_lcore) {
+ rx_lcore_id++;
+ if (rx_lcore_id >= RTE_MAX_LCORE)
+ rte_exit(EXIT_FAILURE, "Not enough cores\n");
+ }
+
+ if (qconf != &lcore_queue_conf[rx_lcore_id]) {
+ /* Assigned a new logical core in the loop above. */
+ qconf = &lcore_queue_conf[rx_lcore_id];
+ nb_lcores++;
+ }
+
+ qconf->rx_port_list[qconf->n_rx_port] = portid;
+ qconf->n_rx_port++;
+ printf("Lcore %u: RX port %u\n", rx_lcore_id, portid);
+ }
+
+ nb_mbufs = RTE_MAX(nb_ports * (nb_rxd + nb_txd + MAX_PKT_BURST +
+ nb_lcores * MEMPOOL_CACHE_SIZE), 8192U);
+
+ /* create the mbuf pool */
+ l2fwd_pktmbuf_pool = rte_pktmbuf_pool_create("mbuf_pool", nb_mbufs,
+ MEMPOOL_CACHE_SIZE, 0, RTE_MBUF_DEFAULT_BUF_SIZE,
+ rte_socket_id());
+ if (l2fwd_pktmbuf_pool == NULL)
+ rte_exit(EXIT_FAILURE, "Cannot init mbuf pool\n");
+
+ if(rx_keep_crc) port_conf.rxmode.offloads |= DEV_RX_OFFLOAD_KEEP_CRC;
+ if(rx_keep_sbp) port_conf.rxmode.offloads |= DEV_RX_OFFLOAD_SAVE_BAD_PACKET;
+ if(tx_disable_pad_crc) port_conf.txmode.offloads |= DEV_TX_OFFLOAD_DISABLE_APPEND_CRC;
+ if(tx_disable_pad_frame) port_conf.txmode.offloads |= DEV_TX_OFFLOAD_DISABLE_APPEND_FRAME;
+
+ /* Initialise each port */
+ RTE_ETH_FOREACH_DEV(portid) {
+ struct rte_eth_rxconf rxq_conf;
+ struct rte_eth_txconf txq_conf;
+ struct rte_eth_conf local_port_conf = port_conf;
+ struct rte_eth_dev_info dev_info;
+
+ /* skip ports that are not enabled */
+ if ((l2fwd_enabled_port_mask & (1 << portid)) == 0) {
+ printf("Skipping disabled port %u\n", portid);
+ continue;
+ }
+ nb_ports_available++;
+
+ /* init port */
+ printf("Initializing port %u... ", portid);
+ fflush(stdout);
+ rte_eth_dev_info_get(portid, &dev_info);
+ if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MBUF_FAST_FREE)
+ local_port_conf.txmode.offloads |=
+ DEV_TX_OFFLOAD_MBUF_FAST_FREE;
+ ret = rte_eth_dev_configure(portid, 1, 1, &local_port_conf);
+ if (ret < 0)
+ rte_exit(EXIT_FAILURE, "Cannot configure device: err=%d, port=%u\n",
+ ret, portid);
+
+ ret = rte_eth_dev_adjust_nb_rx_tx_desc(portid, &nb_rxd,
+ &nb_txd);
+ if (ret < 0)
+ rte_exit(EXIT_FAILURE,
+ "Cannot adjust number of descriptors: err=%d, port=%u\n",
+ ret, portid);
+
+ rte_eth_macaddr_get(portid,&l2fwd_ports_eth_addr[portid]);
+
+ /* init one RX queue */
+ fflush(stdout);
+ rxq_conf = dev_info.default_rxconf;
+ rxq_conf.offloads = local_port_conf.rxmode.offloads;
+ ret = rte_eth_rx_queue_setup(portid, 0, nb_rxd,
+ rte_eth_dev_socket_id(portid),
+ &rxq_conf,
+ l2fwd_pktmbuf_pool);
+ if (ret < 0)
+ rte_exit(EXIT_FAILURE, "rte_eth_rx_queue_setup:err=%d, port=%u\n",
+ ret, portid);
+
+ /* init one TX queue on each port */
+ fflush(stdout);
+ txq_conf = dev_info.default_txconf;
+ txq_conf.offloads = local_port_conf.txmode.offloads;
+ ret = rte_eth_tx_queue_setup(portid, 0, nb_txd,
+ rte_eth_dev_socket_id(portid),
+ &txq_conf);
+ if (ret < 0)
+ rte_exit(EXIT_FAILURE, "rte_eth_tx_queue_setup:err=%d, port=%u\n",
+ ret, portid);
+
+ /* Initialize TX buffers */
+ tx_buffer[portid] = rte_zmalloc_socket("tx_buffer",
+ RTE_ETH_TX_BUFFER_SIZE(MAX_PKT_BURST), 0,
+ rte_eth_dev_socket_id(portid));
+ if (tx_buffer[portid] == NULL)
+ rte_exit(EXIT_FAILURE, "Cannot allocate buffer for tx on port %u\n",
+ portid);
+
+ rte_eth_tx_buffer_init(tx_buffer[portid], MAX_PKT_BURST);
+
+ ret = rte_eth_tx_buffer_set_err_callback(tx_buffer[portid],
+ rte_eth_tx_buffer_count_callback,
+ &port_statistics[portid].dropped);
+ if (ret < 0)
+ rte_exit(EXIT_FAILURE,
+ "Cannot set error callback for tx buffer on port %u\n",
+ portid);
+
+ /* Start device */
+ ret = rte_eth_dev_start(portid);
+ if (ret < 0)
+ rte_exit(EXIT_FAILURE, "rte_eth_dev_start:err=%d, port=%u\n",
+ ret, portid);
+
+ printf("done: \n");
+
+ rte_eth_promiscuous_enable(portid);
+
+ printf("Port %u, MAC address: %02X:%02X:%02X:%02X:%02X:%02X\n\n",
+ portid,
+ l2fwd_ports_eth_addr[portid].addr_bytes[0],
+ l2fwd_ports_eth_addr[portid].addr_bytes[1],
+ l2fwd_ports_eth_addr[portid].addr_bytes[2],
+ l2fwd_ports_eth_addr[portid].addr_bytes[3],
+ l2fwd_ports_eth_addr[portid].addr_bytes[4],
+ l2fwd_ports_eth_addr[portid].addr_bytes[5]);
+
+ /* initialize port stats */
+ memset(&port_statistics, 0, sizeof(port_statistics));
+ }
+
+ if (!nb_ports_available) {
+ rte_exit(EXIT_FAILURE,
+ "All available ports are disabled. Please set portmask.\n");
+ }
+
+ check_all_ports_link_status(l2fwd_enabled_port_mask);
+
+ ret = 0;
+ /* launch per-lcore init on every lcore */
+ rte_eal_mp_remote_launch(l2fwd_launch_one_lcore, NULL, CALL_MASTER);
+ RTE_LCORE_FOREACH_SLAVE(lcore_id) {
+ if (rte_eal_wait_lcore(lcore_id) < 0) {
+ ret = -1;
+ break;
+ }
+ }
+
+ RTE_ETH_FOREACH_DEV(portid) {
+ if ((l2fwd_enabled_port_mask & (1 << portid)) == 0)
+ continue;
+ printf("Closing port %d...", portid);
+ rte_eth_dev_stop(portid);
+ rte_eth_dev_close(portid);
+ printf(" Done\n");
+ }
+ printf("Bye...\n");
+
+ return ret;
+}
diff --git a/examples/tx_only/meson.build b/examples/tx_only/meson.build
new file mode 100644
index 0000000..c34e11e
--- /dev/null
+++ b/examples/tx_only/meson.build
@@ -0,0 +1,11 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2017 Intel Corporation
+
+# meson file, for building this example as part of a main DPDK build.
+#
+# To build this example as a standalone application with an already-installed
+# DPDK instance, use 'make'
+
+sources = files(
+ 'main.c'
+)
diff --git a/install b/install
index e2b99af..8553b92 100755
--- a/install
+++ b/install
@@ -1 +1,11 @@
-rm -rf build; make config T=x86_64-native-linuxapp-gcc && make -j $(($(nproc)-1)) && make install
+#!/bin/bash
+
+rm -rf build
+
+make config T=x86_64-native-linuxapp-gcc && make -j $(($(nproc)-1)) && make install
+
+# 编译 示例程式
+export RTE_SDK="/usr/local/share/dpdk/"
+make -C examples/l2fwd
+make -C examples/tx_only
+make -C examples/l3fwd
diff --git a/lib/librte_ethdev/rte_ethdev.h b/lib/librte_ethdev/rte_ethdev.h
index 1960f3a..379cc03 100644
--- a/lib/librte_ethdev/rte_ethdev.h
+++ b/lib/librte_ethdev/rte_ethdev.h
@@ -957,6 +957,7 @@ struct rte_eth_conf {
#define DEV_RX_OFFLOAD_KEEP_CRC 0x00010000
#define DEV_RX_OFFLOAD_SCTP_CKSUM 0x00020000
#define DEV_RX_OFFLOAD_OUTER_UDP_CKSUM 0x00040000
+#define DEV_RX_OFFLOAD_SAVE_BAD_PACKET 0x10000000 //网卡收包 保存错帧

#define DEV_RX_OFFLOAD_CHECKSUM (DEV_RX_OFFLOAD_IPV4_CKSUM | \
DEV_RX_OFFLOAD_UDP_CKSUM | \
@@ -1019,6 +1020,9 @@ struct rte_eth_conf {
*/
#define DEV_TX_OFFLOAD_MATCH_METADATA 0x00200000

+#define DEV_TX_OFFLOAD_DISABLE_APPEND_FRAME 0x10000000 //禁止网卡填充帧(发送小包时)
+#define DEV_TX_OFFLOAD_DISABLE_APPEND_CRC 0x20000000 //禁止网卡追加4字节CRC
+
#define RTE_ETH_DEV_CAPA_RUNTIME_RX_QUEUE_SETUP 0x00000001
/**< Device supports Rx queue setup after device started*/
#define RTE_ETH_DEV_CAPA_RUNTIME_TX_QUEUE_SETUP 0x00000002

多实例运行

1
2
./tx_only -l 0-1  --file-prefix chunli_1 -w 0000:67:00.0 -- -p 0x1 -T 1 --enable_pkt_gen
./tx_only -l 2-3 --file-prefix chunli_2 -w 0000:68:00.0 -- -p 0x1 -T 1 --rx_keep_sbp