aboutsummaryrefslogtreecommitdiff
path: root/example/generator/odp_generator.c
blob: 1a6bb911f536cbbdb7505cbba97f5f20a93dcf23 (plain)
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
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
/* Copyright (c) 2014-2018, Linaro Limited
 * All rights reserved.
 *
 * SPDX-License-Identifier:     BSD-3-Clause
 */

/** enable strtok */
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif

#include <time.h>
#include <stdlib.h>
#include <getopt.h>
#include <unistd.h>
#include <inttypes.h>
#include <sys/time.h>

#include <example_debug.h>

#include <odp_api.h>

#include <odp/helper/odph_api.h>

#define MAX_WORKERS            32    /* Max number of workers */
#define POOL_NUM_PKT           2048  /* Number of packets in packet pool */
#define POOL_PKT_LEN           1856  /* Max packet length */
#define DEFAULT_PKT_INTERVAL   1000  /* Interval between each packet */
#define DEFAULT_UDP_TX_BURST	16
#define MAX_UDP_TX_BURST	512
#define DEFAULT_RX_BURST	32
#define MAX_RX_BURST		512

#define APPL_MODE_UDP    0			/**< UDP mode */
#define APPL_MODE_PING   1			/**< ping mode */
#define APPL_MODE_RCV    2			/**< receive mode */
#define MAX(a, b) (((a) > (b)) ? (a) : (b))

#define PING_THR_TX 0
#define PING_THR_RX 1

/** print appl mode */
#define PRINT_APPL_MODE(x) printf("%s(%i)\n", #x, (x))

/** Get rid of path in filename - only for unix-type paths using '/' */
#define NO_PATH(file_name) (strrchr((file_name), '/') ? \
			    strrchr((file_name), '/') + 1 : (file_name))

/**
 * Interfaces
 */

typedef struct {
	odp_pktio_t pktio;
	odp_pktio_config_t config;
	odp_pktout_queue_t pktout[MAX_WORKERS];
	unsigned pktout_count;
	odp_pktin_queue_t pktin[MAX_WORKERS];
	unsigned pktin_count;
} interface_t;

/**
 * Parsed command line application arguments
 */
typedef struct {
	int num_workers;	/**< Number of worker thread */
	const char *mask;	/**< CPU mask */
	int if_count;		/**< Number of interfaces to be used */
	char **if_names;	/**< Array of pointers to interface names */
	char *if_str;		/**< Storage for interface names */
	odp_pool_t pool;	/**< Pool for packet IO */
	odph_ethaddr_t srcmac;	/**< src mac addr */
	odph_ethaddr_t dstmac;	/**< dest mac addr */
	unsigned int srcip;	/**< src ip addr */
	unsigned int dstip;	/**< dest ip addr */
	uint16_t srcport;	/**< src udp port */
	uint16_t srcport_end;	/**< src udp end port */
	uint16_t dstport;	/**< dest udp port */
	uint16_t dstport_end;	/**< dest udp end port */
	int mode;		/**< work mode */
	int number;		/**< packets number to be sent */
	int payload;		/**< data len */
	int timeout;		/**< wait time */
	int interval;		/**< wait interval ms between sending
				     each packet */
	int udp_tx_burst;	/**< number of udp packets to send with one
				      API call */
	int rx_burst;	/**< number of packets to receive with one
				      API call */
	odp_bool_t csum;	/**< use platform csum support if available */
	odp_bool_t sched;	/**< use scheduler API to receive packets */
} appl_args_t;

/**
 * counters
*/
typedef struct {
	uint64_t ctr_pkt_snd;	/**< sent packets*/
	uint64_t ctr_pkt_snd_drop; /**< packets dropped in transmit */

	uint64_t ctr_pkt_rcv;	/**< recv packets */
	uint64_t ctr_seq;	/**< ip seq to be send */
	uint64_t ctr_udp_rcv;	/**< udp packets */
	uint64_t ctr_icmp_reply_rcv;	/**< icmp reply packets */
} counters_t;

/** UDP Packet processing function argument */
typedef struct {
	odp_bool_t multi_flow;
	uint16_t srcport_crt;
	uint16_t srcport_start;
	uint16_t srcport_end;
	uint16_t dstport_crt;
	uint16_t dstport_start;
	uint16_t dstport_end;
} udp_args_t;

/** * Thread specific arguments
 */
typedef struct {
	counters_t counters;	/**< Packet conters */
	odp_bool_t stop; /**< Stop packet processing */
	union {
		struct {
			odp_pktout_queue_t pktout; /**< Packet output queue */
			odp_pktout_config_opt_t *pktout_cfg; /**< Packet output config*/
			udp_args_t udp_param;  /**< UDP configuration */
		} tx;
		struct {
			odp_pktin_queue_t pktin; /**< Packet input queue */
		} rx;
	};
	odp_pool_t pool;	/**< Pool for packet IO */
	odp_timer_pool_t tp;	/**< Timer pool handle */
	odp_queue_t tq;		/**< Queue for timeouts */
	odp_timer_t tim;	/**< Timer handle */
	odp_timeout_t tmo_ev;	/**< Timeout event */
	int mode;		/**< Thread mode */
} thread_args_t;

/**
 * Grouping of both parsed CL args and thread specific args - alloc together
 */
typedef struct {
	/** Application (parsed) arguments */
	appl_args_t appl;
	/** Thread specific arguments */
	thread_args_t thread[MAX_WORKERS];
	/** Global arguments */
	int thread_cnt;
	int tx_burst_size;
	int rx_burst_size;
} args_t;

/** Global pointer to args */
static args_t *args;

/** Barrier to sync threads execution */
static odp_barrier_t barrier;

/** Packet processing function types */
typedef odp_packet_t (*setup_pkt_ref_fn_t)(odp_pool_t,
					   odp_pktout_config_opt_t *);
typedef int (*setup_pkt_fn_t)(odp_packet_t, odp_pktout_config_opt_t *,
			      counters_t *, void *);

/* helper funcs */
static void parse_args(int argc, char *argv[], appl_args_t *appl_args);
static void print_info(char *progname, appl_args_t *appl_args);
static void usage(char *progname);
static int scan_ip(char *buf, unsigned int *paddr);
static void print_global_stats(int num_workers);

/**
 * Sleep for the specified amount of milliseconds
 * Use ODP timer, busy wait until timer expired and timeout event received
 */
static void millisleep(uint32_t ms,
		       odp_timer_pool_t tp,
		       odp_timer_t tim,
		       odp_queue_t q,
		       odp_timeout_t tmo)
{
	uint64_t ticks = odp_timer_ns_to_tick(tp, 1000000ULL * ms);
	odp_event_t ev = odp_timeout_to_event(tmo);
	int rc = odp_timer_set_rel(tim, ticks, &ev);

	if (rc != ODP_TIMER_SUCCESS)
		EXAMPLE_ABORT("odp_timer_set_rel() failed\n");
	/* Spin waiting for timeout event */
	while ((ev = odp_queue_deq(q)) == ODP_EVENT_INVALID)
		(void)0;
}

/**
 * Scan ip
 * Parse ip address.
 *
 * @param buf ip address string xxx.xxx.xxx.xx
 * @param paddr ip address for odp_packet
 * @return 1 success, 0 failed
*/
static int scan_ip(char *buf, unsigned int *paddr)
{
	int part1, part2, part3, part4;
	char tail = 0;
	int field;

	if (buf == NULL)
		return 0;

	field = sscanf(buf, "%d . %d . %d . %d %c",
		       &part1, &part2, &part3, &part4, &tail);

	if (field < 4 || field > 5) {
		printf("expect 4 field,get %d/n", field);
		return 0;
	}

	if (tail != 0) {
		printf("ip address mixed with non number/n");
		return 0;
	}

	if ((part1 >= 0 && part1 <= 255) && (part2 >= 0 && part2 <= 255) &&
	    (part3 >= 0 && part3 <= 255) && (part4 >= 0 && part4 <= 255)) {
		if (paddr)
			*paddr = part1 << 24 | part2 << 16 | part3 << 8 | part4;
		return 1;
	} else {
		printf("not good ip %d:%d:%d:%d/n", part1, part2, part3, part4);
	}

	return 0;
}

/**
 * Setup array of reference packets
 *
 * @param pool Packet pool
 * @param pktout_cfg Interface output configuration
 * @param pkt_ref_array Packet array
 * @param pkt_ref_array_size Packet array size
 * @param setup_ref Packet setup function
 * @return 0 success, -1 failed
*/
static int setup_pkt_ref_array(odp_pool_t pool,
			       odp_pktout_config_opt_t *pktout_cfg,
			       odp_packet_t *pkt_ref_array,
			       int pkt_ref_array_size,
			       setup_pkt_ref_fn_t setup_ref)
{
	int i;

	for (i = 0; i < pkt_ref_array_size; i++) {
		pkt_ref_array[i] = (*setup_ref)(pool, pktout_cfg);
		if (pkt_ref_array[i] == ODP_PACKET_INVALID)
			break;
	}

	if (i < pkt_ref_array_size) {
		odp_packet_free_multi(pkt_ref_array, i);
		return -1;
	}
	return 0;
}

/**
 * Setup array of packets
 *
 * @param pktout_cfg Interface output configuration
 * @param pkt_ref_array Reference packet array
 * @param pkt_array Packet array
 * @param pkt_array_size Packet array size
 * @param setup_pkt Packet setup function
 * @return 0 success, -1 failed
*/
static int setup_pkt_array(odp_pktout_config_opt_t *pktout_cfg,
			   counters_t *counters,
			   odp_packet_t *pkt_ref_array,
			   odp_packet_t  *pkt_array,
			   int pkt_array_size,
			   setup_pkt_fn_t setup_pkt,
			   void *setup_pkt_arg)
{
	int i;

	for (i = 0; i < pkt_array_size; i++) {
		if ((*setup_pkt)(pkt_ref_array[i], pktout_cfg, counters,
				 setup_pkt_arg))
			break;

		pkt_array[i] = odp_packet_ref_static(pkt_ref_array[i]);
		if (pkt_array[i] == ODP_PACKET_INVALID)
			break;
	}
	if (i < pkt_array_size) {
		if (i)
			odp_packet_free_multi(pkt_array, i - 1);

		return -1;
	}
	return 0;
}

/**
 * set up an udp packet reference
 *
 * @param pool Buffer pool to create packet in
 * @param pktout_cfg Interface output configuration
 *
 *
 * @retval Handle of created packet
 * @retval ODP_PACKET_INVALID  Packet could not be created
 *
 */
static odp_packet_t setup_udp_pkt_ref(odp_pool_t pool,
				      odp_pktout_config_opt_t *pktout_cfg)
{
	odp_packet_t pkt;
	char *buf;
	odph_ethhdr_t *eth;
	odph_ipv4hdr_t *ip;
	odph_udphdr_t *udp;

	pkt = odp_packet_alloc(pool, args->appl.payload + ODPH_UDPHDR_LEN +
			       ODPH_IPV4HDR_LEN + ODPH_ETHHDR_LEN);

	if (pkt == ODP_PACKET_INVALID)
		return pkt;

	buf = odp_packet_data(pkt);

	/* ether */
	odp_packet_l2_offset_set(pkt, 0);
	eth = (odph_ethhdr_t *)buf;
	memcpy((char *)eth->src.addr, args->appl.srcmac.addr, ODPH_ETHADDR_LEN);
	memcpy((char *)eth->dst.addr, args->appl.dstmac.addr, ODPH_ETHADDR_LEN);
	eth->type = odp_cpu_to_be_16(ODPH_ETHTYPE_IPV4);

	/* ip */
	odp_packet_l3_offset_set(pkt, ODPH_ETHHDR_LEN);
	odp_packet_has_ipv4_set(pkt, 1);
	ip = (odph_ipv4hdr_t *)(buf + ODPH_ETHHDR_LEN);
	ip->dst_addr = odp_cpu_to_be_32(args->appl.dstip);
	ip->src_addr = odp_cpu_to_be_32(args->appl.srcip);
	ip->ver_ihl = ODPH_IPV4 << 4 | ODPH_IPV4HDR_IHL_MIN;
	ip->tot_len = odp_cpu_to_be_16(args->appl.payload + ODPH_UDPHDR_LEN +
				       ODPH_IPV4HDR_LEN);
	ip->proto = ODPH_IPPROTO_UDP;
	ip->id = 0;
	ip->ttl = 64;
	ip->chksum = 0;

	/* udp */
	odp_packet_l4_offset_set(pkt, ODPH_ETHHDR_LEN + ODPH_IPV4HDR_LEN);
	odp_packet_has_udp_set(pkt, 1);
	udp = (odph_udphdr_t *)(buf + ODPH_ETHHDR_LEN + ODPH_IPV4HDR_LEN);
	udp->src_port = odp_cpu_to_be_16(args->appl.srcport);
	udp->dst_port = odp_cpu_to_be_16(args->appl.dstport);
	udp->length = odp_cpu_to_be_16(args->appl.payload + ODPH_UDPHDR_LEN);
	if (!pktout_cfg->bit.udp_chksum) {
		udp->chksum = 0;
		udp->chksum = odph_ipv4_udp_chksum(pkt);
	}

	return pkt;
}

/**
 * set up an udp packet
 *
 * @param pkt Reference UDP packet
 * @param pktout_cfg Interface output configuration
 *
 * @return Success/Failed
 * @retval 0 on success, -1 on fail
 */
static int setup_udp_pkt(odp_packet_t pkt, odp_pktout_config_opt_t *pktout_cfg,
			 counters_t *counters, void *arg)
{
	char *buf;
	odph_ipv4hdr_t *ip;
	unsigned short seq;
	udp_args_t *udp_arg = (udp_args_t *)arg;

	buf = (char *)odp_packet_data(pkt);

	/*Update IP ID and checksum*/
	ip = (odph_ipv4hdr_t *)(buf + ODPH_ETHHDR_LEN);
	seq = counters->ctr_seq % 0xFFFF;
	counters->ctr_seq++;
	ip->id = odp_cpu_to_be_16(seq);
	if (!pktout_cfg->bit.ipv4_chksum) {
		ip->chksum = 0;
		ip->chksum = ~odp_chksum_ones_comp16(ip, ODPH_IPV4HDR_LEN);
	}

	if (udp_arg->multi_flow) {
		odph_udphdr_t *udp = (odph_udphdr_t *)(buf + ODPH_ETHHDR_LEN +
						       ODPH_IPV4HDR_LEN);

		if (udp_arg->srcport_start != udp_arg->srcport_end) {
			udp->src_port = odp_cpu_to_be_16(udp_arg->srcport_crt);
			if (udp_arg->srcport_crt >= udp_arg->srcport_end)
				udp_arg->srcport_crt = udp_arg->srcport_start;
			else
				udp_arg->srcport_crt++;
		}
		if (udp_arg->dstport_start != udp_arg->dstport_end) {
			udp->dst_port = odp_cpu_to_be_16(udp_arg->dstport_crt);
			if (udp_arg->dstport_crt >= udp_arg->dstport_end)
				udp_arg->dstport_crt = udp_arg->dstport_start;
			else
				udp_arg->dstport_crt++;
		}

		udp->chksum = 0;
	}

	if (pktout_cfg->bit.ipv4_chksum || pktout_cfg->bit.udp_chksum) {
		odp_packet_l2_offset_set(pkt, 0);
		odp_packet_l3_offset_set(pkt, ODPH_ETHHDR_LEN);
		odp_packet_l4_offset_set(pkt, ODPH_ETHHDR_LEN +
					 ODPH_IPV4HDR_LEN);
	}
	return 0;
}

/**
 * Set up an icmp packet reference
 *
 * @param pool Buffer pool to create packet in
 * @param pktout_cfg Interface output configuration
 *
 * @return Handle of created packet
 * @retval ODP_PACKET_INVALID  Packet could not be created
 */
static odp_packet_t setup_icmp_pkt_ref(odp_pool_t pool,
				       odp_pktout_config_opt_t *pktout_cfg)
{
	odp_packet_t pkt;
	char *buf;
	odph_ethhdr_t *eth;
	odph_ipv4hdr_t *ip;
	odph_icmphdr_t *icmp;

	(void)pktout_cfg;

	args->appl.payload = 56;
	pkt = odp_packet_alloc(pool, args->appl.payload + ODPH_ICMPHDR_LEN +
		ODPH_IPV4HDR_LEN + ODPH_ETHHDR_LEN);

	if (pkt == ODP_PACKET_INVALID)
		return pkt;

	buf = odp_packet_data(pkt);

	/* ether */
	odp_packet_l2_offset_set(pkt, 0);
	eth = (odph_ethhdr_t *)buf;
	memcpy((char *)eth->src.addr, args->appl.srcmac.addr, ODPH_ETHADDR_LEN);
	memcpy((char *)eth->dst.addr, args->appl.dstmac.addr, ODPH_ETHADDR_LEN);
	eth->type = odp_cpu_to_be_16(ODPH_ETHTYPE_IPV4);
	/* ip */
	odp_packet_l3_offset_set(pkt, ODPH_ETHHDR_LEN);
	ip = (odph_ipv4hdr_t *)(buf + ODPH_ETHHDR_LEN);
	ip->dst_addr = odp_cpu_to_be_32(args->appl.dstip);
	ip->src_addr = odp_cpu_to_be_32(args->appl.srcip);
	ip->ver_ihl = ODPH_IPV4 << 4 | ODPH_IPV4HDR_IHL_MIN;
	ip->ttl = 64;
	ip->tot_len = odp_cpu_to_be_16(args->appl.payload + ODPH_ICMPHDR_LEN +
				       ODPH_IPV4HDR_LEN);
	ip->proto = ODPH_IPPROTO_ICMPV4;
	ip->id = 0;
	ip->chksum = 0;

	/* icmp */
	icmp = (odph_icmphdr_t *)(buf + ODPH_ETHHDR_LEN + ODPH_IPV4HDR_LEN);
	icmp->type = ICMP_ECHO;
	icmp->code = 0;
	icmp->un.echo.id = 0;
	icmp->un.echo.sequence = 0;
	icmp->chksum = 0;

	return pkt;
}

/**
 * Set up an icmp packet
 *
 * @param pkt Reference ICMP packet
 * @param pktout_cfg Interface output configuration
 *
 * @return Success/Failed
 * @retval 0 on success, -1 on fail
 */
static int setup_icmp_pkt(odp_packet_t pkt,
			  odp_pktout_config_opt_t *pktout_cfg,
			  counters_t *counters, void *arg ODP_UNUSED)
{
	char *buf;
	odph_ipv4hdr_t *ip;
	odph_icmphdr_t *icmp;
	uint64_t tval;
	uint8_t *tval_d;
	unsigned short seq;

	buf = (char *)odp_packet_data(pkt);

	/* ip */
	ip = (odph_ipv4hdr_t *)(buf + ODPH_ETHHDR_LEN);
	seq = counters->ctr_seq % 0xffff;
	counters->ctr_seq++;
	ip->id = odp_cpu_to_be_16(seq);
	if (!pktout_cfg->bit.ipv4_chksum) {
		ip->chksum = 0;
		ip->chksum = ~odp_chksum_ones_comp16(ip, ODPH_IPV4HDR_LEN);
	}

	/* icmp */
	icmp = (odph_icmphdr_t *)(buf + ODPH_ETHHDR_LEN + ODPH_IPV4HDR_LEN);
	icmp->un.echo.sequence = ip->id;

	tval_d = (uint8_t *)(buf + ODPH_ETHHDR_LEN + ODPH_IPV4HDR_LEN +
				  ODPH_ICMPHDR_LEN);
	tval = odp_time_to_ns(odp_time_local());
	memcpy(tval_d, &tval, sizeof(uint64_t));

	icmp->chksum = 0;
	icmp->chksum = ~odp_chksum_ones_comp16(icmp, args->appl.payload +
					       ODPH_ICMPHDR_LEN);

	if (pktout_cfg->bit.ipv4_chksum) {
		odp_packet_l2_offset_set(pkt, 0);
		odp_packet_l3_offset_set(pkt, ODPH_ETHHDR_LEN);
		odp_packet_l4_offset_set(pkt, ODPH_ETHHDR_LEN +
					 ODPH_IPV4HDR_LEN);
	}

	return 0;
}

/**
 * Create a pktio object
 *
 * @param dev Name of device to open
 * @param pool Pool to associate with device for packet RX/TX
 *
 * @return The handle of the created pktio object.
 * @warning This routine aborts if the create is unsuccessful.
 */
static int create_pktio(const char *dev, odp_pool_t pool,
			unsigned num_rx_queues,
			unsigned num_tx_queues,
			interface_t *itf)
{
	odp_pktio_capability_t capa;
	int ret;
	odp_pktio_param_t pktio_param;
	odp_pktin_queue_param_t pktin_param;
	odp_pktout_queue_param_t pktout_param;
	odp_pktio_op_mode_t pktout_mode, pktin_mode;
	odp_bool_t sched = args->appl.sched;

	odp_pktio_param_init(&pktio_param);
	pktio_param.in_mode = num_rx_queues ?
		(sched ? ODP_PKTIN_MODE_SCHED : ODP_PKTIN_MODE_DIRECT) :
		ODP_PKTIN_MODE_DISABLED;
	pktio_param.out_mode = num_tx_queues ? ODP_PKTOUT_MODE_DIRECT :
		ODP_PKTOUT_MODE_DISABLED;

	/* Open a packet IO instance */
	itf->pktio = odp_pktio_open(dev, pool, &pktio_param);

	if (itf->pktio == ODP_PKTIO_INVALID) {
		EXAMPLE_ERR("Error: pktio create failed for %s\n", dev);
		return -1;
	}

	if (odp_pktio_capability(itf->pktio, &capa)) {
		EXAMPLE_ERR("Error: Failed to get interface capabilities %s\n",
			    dev);
		return -1;
	}
	odp_pktio_config_init(&itf->config);
	if (args->appl.csum) {
		itf->config.pktin.bit.ipv4_chksum =
			capa.config.pktin.bit.ipv4_chksum;
		itf->config.pktin.bit.udp_chksum =
			capa.config.pktin.bit.udp_chksum;
		itf->config.pktin.bit.drop_ipv4_err =
			capa.config.pktin.bit.drop_ipv4_err;
		itf->config.pktin.bit.drop_udp_err =
			capa.config.pktin.bit.drop_udp_err;

		itf->config.pktout.bit.ipv4_chksum_ena =
			capa.config.pktout.bit.ipv4_chksum_ena;
		itf->config.pktout.bit.udp_chksum_ena =
			capa.config.pktout.bit.udp_chksum_ena;
		itf->config.pktout.bit.ipv4_chksum =
			capa.config.pktout.bit.ipv4_chksum;
		itf->config.pktout.bit.udp_chksum =
			capa.config.pktout.bit.udp_chksum;
	} else { /* explicit disable */
		itf->config.pktin.bit.ipv4_chksum = 0;
		itf->config.pktin.bit.udp_chksum = 0;
		itf->config.pktout.bit.ipv4_chksum_ena = 0;
		itf->config.pktout.bit.udp_chksum_ena = 0;
		itf->config.pktout.bit.ipv4_chksum = 0;
		itf->config.pktout.bit.udp_chksum = 0;
	}

	itf->config.parser.layer = ODP_PROTO_LAYER_L2;
	if (itf->config.pktin.bit.udp_chksum)
		itf->config.parser.layer = ODP_PROTO_LAYER_L4;
	else if (itf->config.pktin.bit.ipv4_chksum)
		itf->config.parser.layer = ODP_PROTO_LAYER_L3;

	if (odp_pktio_config(itf->pktio, &itf->config)) {
		EXAMPLE_ERR("Error: Failed to set interface configuration %s\n",
			    dev);
		return -1;
	}

	if (num_rx_queues) {
		pktin_mode = ODP_PKTIO_OP_MT_UNSAFE;
		if (num_rx_queues > capa.max_input_queues) {
			num_rx_queues = capa.max_input_queues;
			pktin_mode = ODP_PKTIO_OP_MT;
			EXAMPLE_DBG("Warning: Force RX multithread safe mode "
				    "(slower)on %s\n",	dev);
		}

		odp_pktin_queue_param_init(&pktin_param);
		pktin_param.num_queues = num_rx_queues;
		pktin_param.op_mode = pktin_mode;
		if (sched)
			pktin_param.queue_param.sched.sync =
				ODP_SCHED_SYNC_ATOMIC;

		if (odp_pktin_queue_config(itf->pktio, &pktin_param)) {
			EXAMPLE_ERR("Error: pktin queue config failed "
				    "for %s\n", dev);
			return -1;
		}
	}

	if (num_tx_queues) {
		pktout_mode = ODP_PKTIO_OP_MT_UNSAFE;
		if (num_tx_queues > capa.max_output_queues) {
			num_tx_queues = capa.max_output_queues;
			pktout_mode = ODP_PKTIO_OP_MT;
			EXAMPLE_DBG("Warning: Force TX multithread safe mode "
				    "(slower) on %s\n", dev);
		}

		odp_pktout_queue_param_init(&pktout_param);
		pktout_param.num_queues = num_tx_queues;
		pktout_param.op_mode = pktout_mode;

		if (odp_pktout_queue_config(itf->pktio, &pktout_param)) {
			EXAMPLE_ERR("Error: pktout queue config failed for %s\n",
				    dev);
			return -1;
		}
	}

	ret = odp_pktio_start(itf->pktio);
	if (ret)
		EXAMPLE_ABORT("Error: unable to start %s\n", dev);

	itf->pktout_count = num_tx_queues;
	if (itf->pktout_count &&
	    odp_pktout_queue(itf->pktio, itf->pktout, itf->pktout_count) !=
	    (int)itf->pktout_count) {
		EXAMPLE_ERR("Error: failed to get output queues for %s\n", dev);
		return -1;
	}

	itf->pktin_count = num_rx_queues;
	if (!sched && itf->pktin_count &&
	    odp_pktin_queue(itf->pktio, itf->pktin, itf->pktin_count) !=
	    (int)itf->pktin_count) {
		EXAMPLE_ERR("Error: failed to get input queues for %s\n", dev);
		return -1;
	}

	printf("  created pktio:%02" PRIu64
	       ", dev:%s, queue mode (ATOMIC queues)\n"
	       "          default pktio%02" PRIu64 "\n",
	       odp_pktio_to_u64(itf->pktio), dev,
	       odp_pktio_to_u64(itf->pktio));
	fflush(NULL);

	return 0;
}

/**
 * Packet IO loopback worker thread using ODP queues
 *
 * @param arg  thread arguments of type 'thread_args_t *'
 */

static int gen_send_thread(void *arg)
{
	int thr;
	int ret = 0;
	thread_args_t *thr_args;
	odp_pktout_queue_t pktout;
	odp_pktout_config_opt_t *pktout_cfg;
	odp_packet_t pkt_ref_array[MAX_UDP_TX_BURST];
	odp_packet_t pkt_array[MAX_UDP_TX_BURST];
	int pkt_array_size, seq_step;
	int burst_start, burst_size;
	setup_pkt_ref_fn_t setup_pkt_ref = NULL;
	setup_pkt_fn_t setup_pkt = NULL;
	void *setup_pkt_arg = NULL;
	counters_t *counters;
	uint64_t pkt_count_max = 0;

	thr = odp_thread_id();
	thr_args = arg;
	pktout = thr_args->tx.pktout;
	pktout_cfg = thr_args->tx.pktout_cfg;
	counters = &thr_args->counters;

	/* Create reference packets*/
	if (args->appl.mode == APPL_MODE_UDP) {
		setup_pkt_ref = setup_udp_pkt_ref;
		setup_pkt = setup_udp_pkt;
		seq_step = args->tx_burst_size * (args->thread_cnt - 1);
		if (args->appl.number != -1)
			pkt_count_max = args->appl.number / args->thread_cnt +
				(args->appl.number % args->thread_cnt ? 1 : 0);
		setup_pkt_arg = &thr_args->tx.udp_param;
	} else if (args->appl.mode == APPL_MODE_PING) {
		setup_pkt_ref = setup_icmp_pkt_ref;
		setup_pkt = setup_icmp_pkt;
		seq_step = 0;
		if (args->appl.number != -1)
			pkt_count_max = args->appl.number;
	} else {
		EXAMPLE_ERR("  [%02i] Error: invalid processing mode %d\n",
			    thr, args->appl.mode);
		return -1;
	}
	pkt_array_size = args->tx_burst_size;

	if (setup_pkt_ref_array(thr_args->pool, pktout_cfg,
				pkt_ref_array, pkt_array_size,
				setup_pkt_ref)) {
		EXAMPLE_ERR("[%02i] Error: failed to create"
			    " reference packets\n", thr);
		return -1;
	}

	printf("  [%02i] created mode: SEND\n", thr);

	odp_barrier_wait(&barrier);

	for (;;) {
		if (thr_args->stop)
			break;

		if (pkt_count_max && counters->ctr_pkt_snd > pkt_count_max) {
			sleep(1); /* wait for stop command */
			continue;
		}

		/* Setup TX burst*/
		if (setup_pkt_array(pktout_cfg, counters,
				    pkt_ref_array, pkt_array,
				    pkt_array_size, setup_pkt, setup_pkt_arg)) {
			EXAMPLE_ERR("[%02i] Error: failed to setup packets\n",
				    thr);
			break;
		}

		/* Send TX burst*/
		for (burst_start = 0, burst_size = pkt_array_size;;) {
			ret = odp_pktout_send(pktout, &pkt_array[burst_start],
					      burst_size);
			if (ret == burst_size) {
				burst_size = 0;
				break;
			} else if (ret >= 0 && ret < burst_size) {
				thr_args->counters.ctr_pkt_snd_drop +=
					burst_size - ret;

				burst_start += ret;
				burst_size -= ret;
				continue;
			}
			EXAMPLE_ERR("  [%02i] packet send failed\n", thr);
			odp_packet_free_multi(&pkt_array[burst_start],
					      burst_size);
			break;
		}

		counters->ctr_pkt_snd += pkt_array_size - burst_size;

		if (args->appl.interval != 0) {
			printf("  [%02i] send pkt no:%ju seq %ju\n",
			       thr,
			       counters->ctr_seq,
			       counters->ctr_seq % 0xffff);
			millisleep(args->appl.interval,
				   thr_args->tp,
				   thr_args->tim,
				   thr_args->tq,
				   thr_args->tmo_ev);
		}
		counters->ctr_seq += seq_step;
	}

	odp_packet_free_multi(pkt_ref_array, pkt_array_size);

	return 0;
}

/**
 * Process icmp packets
 *
 * @param  thr worker id
 * @param  thr_args worker argument
 * @param  icmp icmp header address
 */

static void process_icmp_pkt(int thr, thread_args_t *thr_args,
			     uint8_t *_icmp)
{
	uint64_t trecv;
	uint64_t tsend;
	uint64_t rtt_ms, rtt_us;
	odph_icmphdr_t *icmp = (odph_icmphdr_t *)_icmp;

	if (icmp->type == ICMP_ECHOREPLY) {
		thr_args->counters.ctr_icmp_reply_rcv++;

		memcpy(&tsend, (uint8_t *)icmp + ODPH_ICMPHDR_LEN,
		       sizeof(uint64_t));
		trecv = odp_time_to_ns(odp_time_local());
		rtt_ms = (trecv - tsend) / ODP_TIME_MSEC_IN_NS;
		rtt_us = (trecv - tsend) / ODP_TIME_USEC_IN_NS -
				1000 * rtt_ms;
		printf("  [%02i] ICMP Echo Reply seq %d time %"
			PRIu64 ".%.03" PRIu64" ms\n", thr,
			odp_be_to_cpu_16(icmp->un.echo.sequence),
			rtt_ms, rtt_us);
	} else if (icmp->type == ICMP_ECHO) {
		printf("  [%02i] ICMP Echo Request\n", thr);
	}
}

/**
 * Process odp packets
 *
 * @param  thr worker id
 * @param  thr_args worker argument
 * @param  pkt_tbl packets to be print
 * @param  len packet number
 */
static void process_pkts(int thr, thread_args_t *thr_args,
			 odp_packet_t pkt_tbl[], unsigned len)
{
	odp_packet_t pkt;
	uint32_t left, offset, i;
	odph_ipv4hdr_t *ip;

	for (i = 0; i < len; ++i) {
		pkt = pkt_tbl[i];

		/* Drop packets with errors */
		if (odp_unlikely(odp_packet_has_error(pkt)))
			continue;

		offset = odp_packet_l3_offset(pkt);
		left = odp_packet_len(pkt) - offset;

		if (left < sizeof(odph_ipv4hdr_t))
			continue;

		ip = (odph_ipv4hdr_t *)((uint8_t *)odp_packet_data(pkt) +
					offset);

		/* only ip pkts */
		if (ODPH_IPV4HDR_VER(ip->ver_ihl) != ODPH_IPV4)
			continue;

		thr_args->counters.ctr_pkt_rcv++;

		/* udp */
		if (ip->proto == ODPH_IPPROTO_UDP) {
			thr_args->counters.ctr_udp_rcv++;
		} else if (ip->proto == ODPH_IPPROTO_ICMPV4) {
			uint32_t l3_size = ODPH_IPV4HDR_IHL(ip->ver_ihl) * 4;

			offset += l3_size;
			left -=  l3_size;

			if (left < sizeof(odph_icmphdr_t))
				continue;

			process_icmp_pkt(thr, thr_args,
					 (uint8_t *)odp_packet_data(pkt) +
					 offset);
		}
	}
}

/**
 * Scheduler receive function
 *
 * @param arg  thread arguments of type 'thread_args_t *'
 */
static int gen_recv_thread(void *arg)
{
	int thr;
	thread_args_t *thr_args;
	odp_packet_t pkts[MAX_RX_BURST];
	odp_event_t events[MAX_RX_BURST], ev;
	int pkt_cnt, ev_cnt, i;
	int burst_size;

	thr = odp_thread_id();
	thr_args = (thread_args_t *)arg;
	burst_size = args->rx_burst_size;

	printf("  [%02i] created mode: RECEIVE SCHEDULER\n", thr);
	odp_barrier_wait(&barrier);

	for (;;) {
		if (thr_args->stop)
			break;

		/* Use schedule to get buf from any input queue */
		ev_cnt = odp_schedule_multi(NULL, ODP_SCHED_NO_WAIT,
					    events, burst_size);
		if (ev_cnt == 0)
			continue;

		for (i = 0, pkt_cnt = 0; i < ev_cnt; i++) {
			ev = events[i];

			if (odp_event_type(ev) == ODP_EVENT_PACKET)
				pkts[pkt_cnt++] = odp_packet_from_event(ev);
			else
				odp_event_free(ev);
		}

		if (pkt_cnt) {
			process_pkts(thr, thr_args, pkts, pkt_cnt);

			odp_packet_free_multi(pkts, pkt_cnt);
		}
	}

	return 0;
}

/**
 * Direct receive function
 *
 * @param arg  thread arguments of type 'thread_args_t *'
 */
static int gen_recv_direct_thread(void *arg)
{
	int thr;
	thread_args_t *thr_args;
	odp_packet_t pkts[MAX_RX_BURST];
	int pkt_cnt, burst_size;
	odp_pktin_queue_t pktin;
	uint64_t wait = odp_pktin_wait_time(ODP_TIME_SEC_IN_NS);

	thr = odp_thread_id();
	thr_args = (thread_args_t *)arg;
	pktin = thr_args->rx.pktin;
	burst_size = args->rx_burst_size;

	printf("  [%02i] created mode: RECEIVE\n", thr);
	odp_barrier_wait(&barrier);

	for (;;) {
		if (thr_args->stop)
			break;

		pkt_cnt = odp_pktin_recv_tmo(pktin, pkts, burst_size, wait);

		if (pkt_cnt > 0) {
			process_pkts(thr, thr_args, pkts, pkt_cnt);

			odp_packet_free_multi(pkts, pkt_cnt);
		} else if (pkt_cnt == 0) {
			continue;
		} else {
			break;
		}
	}

	return 0;
}

#define COUNTER_SUM(_c, _nw)						\
({									\
	int _itr;							\
	uint64_t _result = 0;						\
									\
	for (_itr = 0; _itr < _nw; _itr++)				\
		_result += args->thread[_itr].counters.ctr_ ## _c;	\
									\
	_result;							\
})

static void garceful_stop_ping(void)
{
	uint64_t snd, rcv;

	if (args->appl.mode != APPL_MODE_PING)
		return;

	while (args->appl.timeout >= 0) {
		snd = COUNTER_SUM(pkt_snd, 2);
		rcv = COUNTER_SUM(icmp_reply_rcv, 2);
		if (rcv >= snd)
			break;

		sleep(1);
		args->appl.timeout--;
	}
}

/**
 * printing verbose statistics
 *
 */
static void print_global_stats(int num_workers)
{
	odp_time_t cur, wait, next, left;
	uint64_t pkts_snd = 0, pkts_snd_prev = 0;
	uint64_t pps_snd = 0, maximum_pps_snd = 0;
	uint64_t pkts_rcv = 0, pkts_rcv_prev = 0;
	uint64_t pps_rcv = 0, maximum_pps_rcv = 0;
	uint64_t stall, pkts_snd_drop;
	int verbose_interval = 20, i;
	odp_thrmask_t thrd_mask;

	odp_barrier_wait(&barrier);

	wait = odp_time_local_from_ns(verbose_interval * ODP_TIME_SEC_IN_NS);
	next = odp_time_sum(odp_time_local(), wait);

	while (odp_thrmask_worker(&thrd_mask) == num_workers) {
		if (args->appl.mode != APPL_MODE_RCV &&
		    args->appl.number != -1) {
			uint64_t cnt = COUNTER_SUM(pkt_snd, num_workers);

			if (cnt >= (unsigned int)args->appl.number) {
				garceful_stop_ping();
				break;
			}
		}
		cur = odp_time_local();
		if (odp_time_cmp(next, cur) > 0) {
			left = odp_time_diff(next, cur);
			stall = odp_time_to_ns(left);
			if (stall / ODP_TIME_SEC_IN_NS)
				sleep(1);
			else
				usleep(stall / ODP_TIME_USEC_IN_NS);
			continue;
		}
		next = odp_time_sum(cur, wait);

		switch (args->appl.mode) {
		case APPL_MODE_RCV:
			pkts_rcv = COUNTER_SUM(pkt_rcv, num_workers);
			pkts_snd = 0;
			pkts_snd_drop = 0;
			break;
		case APPL_MODE_PING:
			pkts_snd = COUNTER_SUM(pkt_snd, num_workers);
			pkts_snd_drop = COUNTER_SUM(pkt_snd_drop, num_workers);
			pkts_rcv = COUNTER_SUM(icmp_reply_rcv, num_workers);
			break;
		case APPL_MODE_UDP:
			pkts_snd = COUNTER_SUM(pkt_snd, num_workers);
			pkts_snd_drop = COUNTER_SUM(pkt_snd_drop, num_workers);
			break;
		default:
			continue;
		}

		pps_snd = (pkts_snd - pkts_snd_prev) / verbose_interval;
		pkts_snd_prev = pkts_snd;
		if (pps_snd > maximum_pps_snd)
			maximum_pps_snd = pps_snd;

		pps_rcv = (pkts_rcv - pkts_rcv_prev) / verbose_interval;
		pkts_rcv_prev = pkts_rcv;
		if (pps_rcv > maximum_pps_rcv)
			maximum_pps_rcv = pps_rcv;

		printf("sent: %" PRIu64 ", drops: %" PRIu64 ", "
			"send rate: %" PRIu64 " pps, "
			"max send rate: %" PRIu64 " pps, "
			"rcv: %" PRIu64 ", "
			"recv rate: %" PRIu64 " pps, "
			"max recv rate: %" PRIu64 " pps\n",
			pkts_snd, pkts_snd_drop,
			pps_snd, maximum_pps_snd,
			pkts_rcv, pps_rcv, maximum_pps_rcv);
		fflush(NULL);
	}

	for (i = 0; i < num_workers; i++)
		args->thread[i].stop = 1;
}

/**
 * ODP packet example main function
 */
int main(int argc, char *argv[])
{
	odph_odpthread_t thread_tbl[MAX_WORKERS];
	odp_pool_t pool;
	int num_workers;
	unsigned num_rx_queues, num_tx_queues;
	int i;
	odp_shm_t shm;
	odp_cpumask_t cpumask;
	char cpumaskstr[ODP_CPUMASK_STR_SIZE];
	odp_pool_param_t params;
	odp_timer_pool_param_t tparams;
	odp_timer_pool_t tp;
	odp_pool_t tmop;
	odp_queue_t tq;
	odp_event_t ev;
	interface_t *ifs;
	odp_instance_t instance;
	odph_odpthread_params_t thr_params;
	odp_timer_capability_t timer_capa;

	/* Init ODP before calling anything else */
	if (odp_init_global(&instance, NULL, NULL)) {
		EXAMPLE_ERR("Error: ODP global init failed.\n");
		exit(EXIT_FAILURE);
	}

	if (odp_init_local(instance, ODP_THREAD_CONTROL)) {
		EXAMPLE_ERR("Error: ODP local init failed.\n");
		exit(EXIT_FAILURE);
	}

	/* Reserve memory for args from shared mem */
	shm = odp_shm_reserve("shm_args", sizeof(args_t),
			      ODP_CACHE_LINE_SIZE, 0);
	args = odp_shm_addr(shm);

	if (args == NULL) {
		EXAMPLE_ERR("Error: shared mem alloc failed.\n");
		exit(EXIT_FAILURE);
	}
	memset(args, 0, sizeof(*args));

	/* Parse and store the application arguments */
	parse_args(argc, argv, &args->appl);

	/* Print both system and application information */
	print_info(NO_PATH(argv[0]), &args->appl);

	/* Default to max number of workers, unless user specified number of
	 * workers or cpumask */
	num_workers = MAX_WORKERS;
	num_workers = odp_cpumask_default_worker(&cpumask, num_workers);

	if (args->appl.num_workers) {
		/* -w option: number of workers */
		num_workers = args->appl.num_workers;
		num_workers = odp_cpumask_default_worker(&cpumask, num_workers);
	} else if (args->appl.mask) {
		/* -c option: cpumask */
		odp_cpumask_from_str(&cpumask, args->appl.mask);
		num_workers = odp_cpumask_count(&cpumask);
	}

	(void)odp_cpumask_to_str(&cpumask, cpumaskstr, sizeof(cpumaskstr));

	printf("num worker threads: %i\n", num_workers);
	printf("first CPU:          %i\n", odp_cpumask_first(&cpumask));
	printf("cpu mask:           %s\n", cpumaskstr);
	fflush(NULL);

	/* ping mode need two workers */
	if (args->appl.mode == APPL_MODE_PING) {
		if (num_workers < 2) {
			EXAMPLE_ERR("Need at least two worker threads\n");
			exit(EXIT_FAILURE);
		} else {
			num_workers = 2;
		}
	}
	args->thread_cnt = num_workers;

	/* Burst size */
	if (args->appl.mode == APPL_MODE_PING) {
		args->tx_burst_size = 1;
		args->rx_burst_size = 1;
	} else if (args->appl.mode == APPL_MODE_UDP) {
		args->tx_burst_size = args->appl.udp_tx_burst;
		args->rx_burst_size = 0;
	} else {
		args->tx_burst_size = 0;
		args->rx_burst_size = args->appl.rx_burst;
	}

	/* Create packet pool */
	odp_pool_param_init(&params);
	params.pkt.seg_len = POOL_PKT_LEN;
	params.pkt.len     = POOL_PKT_LEN;
	params.pkt.num     = POOL_NUM_PKT;
	params.type        = ODP_POOL_PACKET;

	pool = odp_pool_create("packet_pool", &params);

	if (pool == ODP_POOL_INVALID) {
		EXAMPLE_ERR("Error: packet pool create failed.\n");
		exit(EXIT_FAILURE);
	}
	odp_pool_print(pool);

	/* Create timer pool */
	if (odp_timer_capability(ODP_CLOCK_CPU, &timer_capa)) {
		EXAMPLE_ERR("Error: get timer capacity failed.\n");
		exit(EXIT_FAILURE);
	}
	tparams.res_ns = MAX(1 * ODP_TIME_MSEC_IN_NS,
			     timer_capa.highest_res_ns);
	tparams.min_tmo = 0;
	tparams.max_tmo = 10000 * ODP_TIME_SEC_IN_NS;
	tparams.num_timers = num_workers; /* One timer per worker */
	tparams.priv = 0; /* Shared */
	tparams.clk_src = ODP_CLOCK_CPU;
	tp = odp_timer_pool_create("timer_pool", &tparams);
	if (tp == ODP_TIMER_POOL_INVALID) {
		EXAMPLE_ERR("Timer pool create failed.\n");
		exit(EXIT_FAILURE);
	}
	odp_timer_pool_start();

	/* Create timeout pool */
	odp_pool_param_init(&params);
	params.tmo.num     = tparams.num_timers; /* One timeout per timer */
	params.type	   = ODP_POOL_TIMEOUT;

	tmop = odp_pool_create("timeout_pool", &params);
	if (tmop == ODP_POOL_INVALID) {
		EXAMPLE_ERR("Error: timeout pool create failed.\n");
		exit(EXIT_FAILURE);
	}

	ifs = malloc(sizeof(interface_t) * args->appl.if_count);

	for (i = 0; i < args->appl.if_count; ++i) {
		if (args->appl.mode == APPL_MODE_PING) {
			num_rx_queues = 1;
			num_tx_queues = 1;
		} else if (args->appl.mode == APPL_MODE_UDP) {
			num_rx_queues = 0;
			num_tx_queues = num_workers / args->appl.if_count;
			if (i < num_workers % args->appl.if_count)
				num_tx_queues++;
		} else { /* APPL_MODE_RCV*/
			num_rx_queues = num_workers / args->appl.if_count;
			if (i < num_workers % args->appl.if_count)
				num_rx_queues++;
			num_tx_queues = 0;
		}

		if (create_pktio(args->appl.if_names[i], pool, num_rx_queues,
				 num_tx_queues, &ifs[i])) {
			EXAMPLE_ERR("Error: create interface %s failed.\n",
				    args->appl.if_names[i]);
			exit(EXIT_FAILURE);
		}
	}

	/* Create and init worker threads */
	memset(thread_tbl, 0, sizeof(thread_tbl));

	/* Init threads params */
	memset(&thr_params, 0, sizeof(thr_params));
	thr_params.thr_type = ODP_THREAD_WORKER;
	thr_params.instance = instance;

	/* num workers + print thread */
	odp_barrier_init(&barrier, num_workers + 1);

	if (args->appl.mode == APPL_MODE_PING) {
		odp_cpumask_t cpu_mask;
		int cpu_first, cpu_next;
		thread_args_t *thr_args;

		odp_cpumask_zero(&cpu_mask);
		cpu_first = odp_cpumask_first(&cpumask);
		odp_cpumask_set(&cpu_mask, cpu_first);

		tq = odp_queue_create("", NULL);
		if (tq == ODP_QUEUE_INVALID) {
			EXAMPLE_ERR("queue_create failed\n");
			abort();
		}
		thr_args = &args->thread[PING_THR_RX];
		if (!args->appl.sched)
			thr_args->rx.pktin = ifs[0].pktin[0];
		thr_args->pool = pool;
		thr_args->tp = tp;
		thr_args->tq = tq;
		thr_args->tim = odp_timer_alloc(tp, tq, NULL);
		if (thr_args->tim == ODP_TIMER_INVALID) {
			EXAMPLE_ERR("timer_alloc failed\n");
			abort();
		}
		thr_args->tmo_ev = odp_timeout_alloc(tmop);
		if (thr_args->tmo_ev == ODP_TIMEOUT_INVALID) {
			EXAMPLE_ERR("timeout_alloc failed\n");
			abort();
		}
		thr_args->mode = args->appl.mode;

		memset(&thr_params, 0, sizeof(thr_params));
		if (args->appl.sched)
			thr_params.start = gen_recv_thread;
		else
			thr_params.start = gen_recv_direct_thread;
		thr_params.arg      = thr_args;
		thr_params.thr_type = ODP_THREAD_WORKER;
		thr_params.instance = instance;

		odph_odpthreads_create(&thread_tbl[PING_THR_RX],
				       &cpu_mask, &thr_params);

		tq = odp_queue_create("", NULL);
		if (tq == ODP_QUEUE_INVALID) {
			EXAMPLE_ERR("queue_create failed\n");
			abort();
		}
		thr_args = &args->thread[PING_THR_TX];
		thr_args->tx.pktout = ifs[0].pktout[0];
		thr_args->tx.pktout_cfg = &ifs[0].config.pktout;
		thr_args->pool = pool;
		thr_args->tp = tp;
		thr_args->tq = tq;
		thr_args->tim = odp_timer_alloc(tp, tq, NULL);
		if (thr_args->tim == ODP_TIMER_INVALID) {
			EXAMPLE_ERR("timer_alloc failed\n");
			abort();
		}
		thr_args->tmo_ev = odp_timeout_alloc(tmop);
		if (thr_args->tmo_ev == ODP_TIMEOUT_INVALID) {
			EXAMPLE_ERR("timeout_alloc failed\n");
			abort();
		}
		thr_args->mode = args->appl.mode;
		cpu_next = odp_cpumask_next(&cpumask, cpu_first);
		odp_cpumask_zero(&cpu_mask);
		odp_cpumask_set(&cpu_mask, cpu_next);

		thr_params.start = gen_send_thread;
		thr_params.arg   = thr_args;

		odph_odpthreads_create(&thread_tbl[PING_THR_TX],
				       &cpu_mask, &thr_params);

	} else {
		int cpu = odp_cpumask_first(&cpumask);
		udp_args_t *udp_param = NULL;
		uint16_t sport_range = args->appl.srcport_end -
			args->appl.srcport + 1;
		uint16_t dport_range = args->appl.dstport_end -
			args->appl.dstport + 1;
		float sport_step = (float)(sport_range) / num_workers;
		float dport_step = (float)(dport_range) / num_workers;
		odp_bool_t multi_flow = false;

		if (sport_range > 1 || dport_range > 1)
			multi_flow = true;

		for (i = 0; i < num_workers; ++i) {
			odp_cpumask_t thd_mask;
			int (*thr_run_func)(void *);
			int if_idx, pktq_idx;
			uint64_t start_seq;

			if_idx = i % args->appl.if_count;

			if (args->appl.mode == APPL_MODE_RCV) {
				pktq_idx = (i / args->appl.if_count) %
					ifs[if_idx].pktin_count;
				if (!args->appl.sched)
					args->thread[i].rx.pktin =
						ifs[if_idx].pktin[pktq_idx];
			} else {
				udp_param = &args->thread[i].tx.udp_param;

				pktq_idx = (i / args->appl.if_count) %
					ifs[if_idx].pktout_count;
				start_seq = i * args->tx_burst_size;

				args->thread[i].tx.pktout =
					ifs[if_idx].pktout[pktq_idx];
				args->thread[i].tx.pktout_cfg =
					&ifs[if_idx].config.pktout;

				udp_param->multi_flow = multi_flow;
				udp_param->srcport_start = args->appl.srcport;
				udp_param->srcport_end = args->appl.srcport_end;
				udp_param->srcport_crt = args->appl.srcport;
				if (sport_range > 1)
					udp_param->srcport_crt +=
						(uint16_t)(i * sport_step);

				udp_param->dstport_start = args->appl.dstport;
				udp_param->dstport_end = args->appl.dstport_end;
				udp_param->dstport_crt = args->appl.dstport;
				if (dport_range > 1)
					udp_param->dstport_crt +=
						(uint16_t)(i * dport_step);

				args->thread[i].counters.ctr_seq = start_seq;
			}
			tq = odp_queue_create("", NULL);
			if (tq == ODP_QUEUE_INVALID) {
				EXAMPLE_ERR("queue_create failed\n");
				abort();
			}
			args->thread[i].pool = pool;
			args->thread[i].tp = tp;
			args->thread[i].tq = tq;
			args->thread[i].tim = odp_timer_alloc(tp, tq, NULL);
			if (args->thread[i].tim == ODP_TIMER_INVALID) {
				EXAMPLE_ERR("timer_alloc failed\n");
				abort();
			}
			args->thread[i].tmo_ev = odp_timeout_alloc(tmop);
			if (args->thread[i].tmo_ev == ODP_TIMEOUT_INVALID) {
				EXAMPLE_ERR("timeout_alloc failed\n");
				abort();
			}
			args->thread[i].mode = args->appl.mode;

			if (args->appl.mode == APPL_MODE_UDP) {
				thr_run_func = gen_send_thread;
			} else if (args->appl.mode == APPL_MODE_RCV) {
				if (args->appl.sched)
					thr_run_func = gen_recv_thread;
				else
					thr_run_func = gen_recv_direct_thread;
			} else {
				EXAMPLE_ERR("ERR MODE\n");
				exit(EXIT_FAILURE);
			}
			/*
			 * Create threads one-by-one instead of all-at-once,
			 * because each thread might get different arguments.
			 * Calls odp_thread_create(cpu) for each thread
			 */
			odp_cpumask_zero(&thd_mask);
			odp_cpumask_set(&thd_mask, cpu);

			thr_params.start = thr_run_func;
			thr_params.arg   = &args->thread[i];

			odph_odpthreads_create(&thread_tbl[i],
					       &thd_mask, &thr_params);
			cpu = odp_cpumask_next(&cpumask, cpu);
		}
	}

	print_global_stats(num_workers);

	/* Master thread waits for other threads to exit */
	for (i = 0; i < num_workers; ++i)
		odph_odpthreads_join(&thread_tbl[i]);

	for (i = 0; i < args->appl.if_count; ++i)
		odp_pktio_stop(ifs[i].pktio);

	for (i = 0; i < num_workers; ++i) {
		odp_timer_cancel(args->thread[i].tim, &ev);
		odp_timer_free(args->thread[i].tim);
		odp_timeout_free(args->thread[i].tmo_ev);
	}

	for (i = 0; i < num_workers; ++i) {
		while (1) {
			ev = odp_queue_deq(args->thread[i].tq);
			if (ev == ODP_EVENT_INVALID)
				break;
			odp_event_free(ev);
		}
		odp_queue_destroy(args->thread[i].tq);
	}

	for (i = 0; i < args->appl.if_count; ++i)
		odp_pktio_close(ifs[i].pktio);
	free(ifs);
	free(args->appl.if_names);
	free(args->appl.if_str);
	if (0 != odp_pool_destroy(pool))
		fprintf(stderr, "unable to destroy pool \"pool\"\n");
	odp_timer_pool_destroy(tp);
	if (0 != odp_pool_destroy(tmop))
		fprintf(stderr, "unable to destroy pool \"tmop\"\n");
	if (0 != odp_shm_free(shm))
		fprintf(stderr, "unable to free \"shm\"\n");
	odp_term_local();
	odp_term_global(instance);
	printf("Exit\n\n");

	return 0;
}

/**
 * Parse and store the command line arguments
 *
 * @param argc       argument count
 * @param argv[]     argument vector
 * @param appl_args  Store application arguments here
 */
static void parse_args(int argc, char *argv[], appl_args_t *appl_args)
{
	int opt;
	int long_index;
	char *token;
	size_t len;
	odp_cpumask_t cpumask, cpumask_args, cpumask_and;
	int i, num_workers;
	static const struct option longopts[] = {
		{"interface", required_argument, NULL, 'I'},
		{"workers", required_argument, NULL, 'w'},
		{"cpumask", required_argument, NULL, 'c'},
		{"srcmac", required_argument, NULL, 'a'},
		{"dstmac", required_argument, NULL, 'b'},
		{"srcip", required_argument, NULL, 's'},
		{"dstip", required_argument, NULL, 'd'},
		{"srcport", required_argument, NULL, 'e'},
		{"srcport_end", required_argument, NULL, 'j'},
		{"dstport", required_argument, NULL, 'f'},
		{"dstport_end", required_argument, NULL, 'k'},
		{"packetsize", required_argument, NULL, 'p'},
		{"mode", required_argument, NULL, 'm'},
		{"count", required_argument, NULL, 'n'},
		{"timeout", required_argument, NULL, 't'},
		{"interval", required_argument, NULL, 'i'},
		{"help", no_argument, NULL, 'h'},
		{"udp_tx_burst", required_argument, NULL, 'x'},
		{"rx_burst", required_argument, NULL, 'r'},
		{"csum", no_argument, NULL, 'y'},
		{"sched", no_argument, NULL, 'z'},
		{NULL, 0, NULL, 0}
	};

	static const char *shortopts = "+I:a:b:s:d:p:i:m:n:t:w:c:x:he:j:f:k"
					":yr:z";

	/* let helper collect its own arguments (e.g. --odph_proc) */
	argc = odph_parse_options(argc, argv);

	appl_args->mode = -1; /* Invalid, must be changed by parsing */
	appl_args->number = -1;
	appl_args->payload = 56;
	appl_args->timeout = -1;
	appl_args->interval = DEFAULT_PKT_INTERVAL;
	appl_args->udp_tx_burst = DEFAULT_UDP_TX_BURST;
	appl_args->rx_burst = DEFAULT_RX_BURST;
	appl_args->srcport = 0;
	appl_args->srcport_end = 0;
	appl_args->dstport = 0;
	appl_args->dstport_end = 0;
	appl_args->csum = 0;
	appl_args->sched = 0;

	while (1) {
		opt = getopt_long(argc, argv, shortopts, longopts, &long_index);
		if (opt == -1)
			break;	/* No more options */

		switch (opt) {
		case 'w':
			appl_args->num_workers = atoi(optarg);
			break;
		case 'c':
			appl_args->mask = optarg;
			odp_cpumask_from_str(&cpumask_args, args->appl.mask);
			num_workers = odp_cpumask_default_worker(&cpumask, 0);
			odp_cpumask_and(&cpumask_and, &cpumask_args, &cpumask);
			if (odp_cpumask_count(&cpumask_and) <
			    odp_cpumask_count(&cpumask_args)) {
				EXAMPLE_ERR("Wrong cpu mask, max cpu's:%d\n",
					    num_workers);
				exit(EXIT_FAILURE);
			}
			break;
		/* parse packet-io interface names */
		case 'I':
			len = strlen(optarg);
			if (len == 0) {
				usage(argv[0]);
				exit(EXIT_FAILURE);
			}
			len += 1;	/* add room for '\0' */

			appl_args->if_str = malloc(len);
			if (appl_args->if_str == NULL) {
				usage(argv[0]);
				exit(EXIT_FAILURE);
			}

			/* count the number of tokens separated by ',' */
			strcpy(appl_args->if_str, optarg);
			for (token = strtok(appl_args->if_str, ","), i = 0;
			     token != NULL;
			     token = strtok(NULL, ","), i++)
				;

			appl_args->if_count = i;

			if (appl_args->if_count == 0) {
				usage(argv[0]);
				exit(EXIT_FAILURE);
			}

			/* allocate storage for the if names */
			appl_args->if_names =
			    calloc(appl_args->if_count, sizeof(char *));

			/* store the if names (reset names string) */
			strcpy(appl_args->if_str, optarg);
			for (token = strtok(appl_args->if_str, ","), i = 0;
			     token != NULL; token = strtok(NULL, ","), i++) {
				appl_args->if_names[i] = token;
			}
			break;

		case 'm':
			if (optarg[0] == 'u') {
				appl_args->mode = APPL_MODE_UDP;
			} else if (optarg[0] == 'p') {
				appl_args->mode = APPL_MODE_PING;
			} else if (optarg[0] == 'r') {
				appl_args->mode = APPL_MODE_RCV;
			} else {
				EXAMPLE_ERR("wrong mode!\n");
				exit(EXIT_FAILURE);
			}
			break;

		case 'a':
			if (odph_eth_addr_parse(&appl_args->srcmac, optarg)) {
				EXAMPLE_ERR("wrong src mac:%s\n", optarg);
				exit(EXIT_FAILURE);
			}
			break;

		case 'b':
			if (odph_eth_addr_parse(&appl_args->dstmac, optarg)) {
				EXAMPLE_ERR("wrong dst mac:%s\n", optarg);
				exit(EXIT_FAILURE);
			}
			break;

		case 's':
			if (scan_ip(optarg, &appl_args->srcip) != 1) {
				EXAMPLE_ERR("wrong src ip:%s\n", optarg);
				exit(EXIT_FAILURE);
			}
			break;

		case 'd':
			if (scan_ip(optarg, &appl_args->dstip) != 1) {
				EXAMPLE_ERR("wrong dst ip:%s\n", optarg);
				exit(EXIT_FAILURE);
			}
			break;

		case 'e':
			appl_args->srcport = (unsigned short)atoi(optarg);
			break;
		case 'j':
			appl_args->srcport_end = (unsigned short)atoi(optarg);
			break;
		case 'f':
			appl_args->dstport = (unsigned short)atoi(optarg);
			break;
		case 'k':
			appl_args->dstport_end = (unsigned short)atoi(optarg);
			break;
		case 'p':
			appl_args->payload = atoi(optarg);
			break;

		case 'n':
			appl_args->number = atoi(optarg);
			break;

		case 't':
			appl_args->timeout = atoi(optarg);
			break;

		case 'i':
			appl_args->interval = atoi(optarg);
			if (appl_args->interval <= 200 && geteuid() != 0) {
				EXAMPLE_ERR("should be root user\n");
				exit(EXIT_FAILURE);
			}
			break;
		case 'x':
			appl_args->udp_tx_burst = atoi(optarg);
			if (appl_args->udp_tx_burst >  MAX_UDP_TX_BURST) {
				EXAMPLE_ERR("wrong UDP Tx burst size (max %d)\n",
					    MAX_UDP_TX_BURST);
				exit(EXIT_FAILURE);
			}
			break;
		case 'r':
			appl_args->rx_burst = atoi(optarg);
			if (appl_args->rx_burst >  MAX_RX_BURST) {
				EXAMPLE_ERR("wrong Rx burst size (max %d)\n",
					    MAX_RX_BURST);
				exit(EXIT_FAILURE);
			}
			break;

		case 'y':
			appl_args->csum = 1;
			break;
		case 'z':
			appl_args->sched = 1;
			break;
		case 'h':
			usage(argv[0]);
			exit(EXIT_SUCCESS);
			break;

		default:
			break;
		}
	}

	if (appl_args->if_count == 0 || appl_args->mode == -1) {
		usage(argv[0]);
		exit(EXIT_FAILURE);
	}

	if ((appl_args->srcport != 0 && appl_args->srcport_end == 0) ||
	    (appl_args->srcport_end < appl_args->srcport))
		appl_args->srcport_end = appl_args->srcport;

	if ((appl_args->dstport != 0 && appl_args->dstport_end == 0) ||
	    (appl_args->dstport_end < appl_args->dstport))
		appl_args->dstport_end = appl_args->dstport;

	optind = 1;		/* reset 'extern optind' from the getopt lib */
}

/**
 * Print system and application info
 */
static void print_info(char *progname, appl_args_t *appl_args)
{
	int i;

	odp_sys_info_print();

	printf("Running ODP appl: \"%s\"\n"
	       "-----------------\n"
	       "IF-count:        %i\n"
	       "Using IFs:      ",
	       progname, appl_args->if_count);
	for (i = 0; i < appl_args->if_count; ++i)
		printf(" %s", appl_args->if_names[i]);
	printf("\n"
	       "Mode:            ");
	if (appl_args->mode == 0)
		PRINT_APPL_MODE(APPL_MODE_UDP);
	else if (appl_args->mode == 1)
		PRINT_APPL_MODE(APPL_MODE_PING);
	else
		PRINT_APPL_MODE(APPL_MODE_RCV);
	printf("\n\n");
	fflush(NULL);
}

/**
 * Prinf usage information
 */
static void usage(char *progname)
{
	printf("\n"
	       "Usage: %s OPTIONS\n"
	       "  E.g. %s -I eth1 -r\n"
	       "\n"
	       "OpenDataPlane example application.\n"
	       "\n"
	       "  Work mode:\n"
	       "    1.send ipv4 udp packets\n"
	       "      odp_generator -I eth0 --srcmac fe:0f:97:c9:e0:44  --dstmac 32:cb:9b:27:2f:1a --srcip 192.168.0.1 --dstip 192.168.0.2 -m u\n"
	       "    2.receive ipv4 packets\n"
	       "      odp_generator -I eth0 -m r\n"
	       "    3.work likes ping\n"
	       "      odp_generator -I eth0 --srcmac fe:0f:97:c9:e0:44  --dstmac 32:cb:9b:27:2f:1a --srcip 192.168.0.1 --dstip 192.168.0.2 --cpumask 0xc -m p\n"
	       "\n"
	       "Mandatory OPTIONS:\n"
	       "  -I, --interface Eth interfaces (comma-separated, no spaces)\n"
	       "  -a, --srcmac src mac address\n"
	       "  -b, --dstmac dst mac address\n"
	       "  -s, --srcip src ip address\n"
	       "  -d, --dstip dst ip address\n"
	       "  -m, --mode work mode: send udp(u), receive(r), send icmp(p)\n"
	       "\n"
	       "Optional OPTIONS\n"
	       "  -h, --help       Display help and exit.\n"
	       "  -e, --srcport udp source port start value\n"
	       "                 default is 0\n"
	       "  -j, --srcport_end udp source port end value\n"
	       "                 default is udp source port start value\n"
	       "  -f, --dstport udp destination port start value\n"
	       "                 default is 0\n"
	       "  -k, --dstport_end udp destination port end value\n"
	       "                 default is udp destination port start value\n"
	       "  -p, --packetsize payload length of the packets\n"
	       "  -t, --timeout only for ping mode, wait ICMP reply timeout seconds\n"
	       "  -i, --interval wait interval ms between sending each packet\n"
	       "                 default is 1000ms. 0 for flood mode\n"
	       "  -w, --workers specify number of workers need to be assigned to application\n"
	       "	         default is to assign all\n"
	       "  -n, --count the number of packets to be send\n"
	       "  -c, --cpumask to set on cores\n"
	       "  -x, --udp_tx_burst size of UDP TX burst\n"
	       "  -r, --rx_burst size of RX burst\n"
	       "  -y, --csum use platform checksum support if available\n"
	       "	         default is disabled\n"
	       "  -z, --sched use scheduler API to receive packets\n"
	       "                 default is direct mode API\n"
	       "\n", NO_PATH(progname), NO_PATH(progname)
	      );
}