DPDK logo

Elixir Cross Referencer

   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
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
/*-
 * Copyright (c) <2010>, Intel Corporation
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * - Redistributions of source code must retain the above copyright
 *   notice, this list of conditions and the following disclaimer.
 *
 * - Redistributions in binary form must reproduce the above copyright
 *   notice, this list of conditions and the following disclaimer in
 *   the documentation and/or other materials provided with the
 *   distribution.
 *
 * - Neither the name of Intel Corporation nor the names of its
 *   contributors may be used to endorse or promote products derived
 *   from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 * OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/**
 * Copyright (c) <2010-2014>, Wind River Systems, Inc. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification, are
 * permitted provided that the following conditions are met:
 *
 * 1) Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 *
 * 2) Redistributions in binary form must reproduce the above copyright notice,
 * this list of conditions and the following disclaimer in the documentation and/or
 * other materials provided with the distribution.
 *
 * 3) Neither the name of Wind River Systems nor the names of its contributors may be
 * used to endorse or promote products derived from this software without specific
 * prior written permission.
 *
 * 4) The screens displayed by the application must contain the copyright notice as defined
 * above and can not be removed without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
/* Created 2010 by Keith Wiles @ intel.com */

#include "pktgen-cmds.h"

#include "pktgen-display.h"
#include "pktgen.h"

/**************************************************************************//**
 *
 * pktgen_save - Save a configuration as a startup script
 *
 * DESCRIPTION
 * Save a configuration as a startup script
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

int
pktgen_save(char *path)
{
	port_info_t   *info;
	pkt_seq_t     *pkt;
	range_info_t  *range;
	uint32_t flags;
	char buff[64];
	FILE      *fd;
	int i, j;
	uint64_t lcore;
	struct ether_addr eaddr;

	fd = fopen(path, "w");
	if (fd == NULL)
		return -1;

	for (i = 0, lcore = 0; i < RTE_MAX_LCORE; i++)
		if (rte_lcore_is_enabled(i) )
			lcore |= (1 << i);

	fprintf(fd, "#\n# Pktgen - %s\n", pktgen_version());
	fprintf(fd, "# %s, %s\n\n", wr_copyright_msg(), wr_powered_by());

	/* TODO: Determine DPDK arguments for rank and memory, default for now. */
	fprintf(fd, "# Command line arguments: (DPDK args are defaults)\n");
	fprintf(fd,
	        "# %s -c %lx -n 3 -m 512 --proc-type %s -- ",
	        pktgen.argv[0],
	        lcore,
	        (rte_eal_process_type() ==
	         RTE_PROC_PRIMARY) ? "primary" : "secondary");
	for (i = 1; i < pktgen.argc; i++)
		fprintf(fd, "%s ", pktgen.argv[i]);
	fprintf(fd, "\n\n");

	fprintf(fd,
	        "#######################################################################\n");
	fprintf(fd, "# Pktgen Configuration script information:\n");
	fprintf(fd,
	        "#   GUI socket is %s\n",
	        (pktgen.flags & ENABLE_GUI_FLAG) ? "Enabled" : "Not Enabled");
	fprintf(fd, "#   Flags %08x\n", pktgen.flags);
	fprintf(fd, "#   Number of ports: %d\n", pktgen.nb_ports);
	fprintf(fd, "#   Number ports per page: %d\n",
	        pktgen.nb_ports_per_page);
	fprintf(fd,
	        "#   Number descriptors: RX %d TX: %d\n",
	        pktgen.nb_rxd,
	        pktgen.nb_txd);
	fprintf(fd, "#   Promiscuous mode is %s\n\n",
	        (pktgen.flags & PROMISCUOUS_ON_FLAG) ? "Enabled" : "Disabled");

#if 0
	fprintf(fd, "# Port Descriptions (-- = blacklisted port):\n");
	for (i = 0; i < RTE_MAX_ETHPORTS; i++)
		if (pktgen.portdesc[i] && strlen((char *)pktgen.portdesc[i]) ) {
			if ( (pktgen.enabled_port_mask & (1 << i)) == 0)
				strcpy(buff, "--");
			else
				strcpy(buff, "++");

			fprintf(fd, "#   %s %s\n", buff, pktgen.portdesc[i]);
		}

#endif
	fprintf(fd,
	        "\n#######################################################################\n");

	fprintf(fd, "# Global configuration:\n");
	uint16_t rows, cols;
	pktgen_display_get_geometry(&rows, &cols);
	fprintf(fd, "geometry %dx%d\n", cols, rows);
	fprintf(fd,
	        "mac_from_arp %s\n\n",
	        (pktgen.flags & MAC_FROM_ARP_FLAG) ? "enable" : "disable");

	for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
		info = &pktgen.info[i];
		pkt = &info->seq_pkt[SINGLE_PKT];
		range = &info->range;

		if (info->tx_burst == 0)
			continue;

		fprintf(fd,
		        "######################### Port %2d ##################################\n",
		        i);
		if (rte_atomic64_read(&info->transmit_count) == 0)
			strcpy(buff, "Forever");
		else
			snprintf(buff, sizeof(buff), "%ld",
			         rte_atomic64_read(&info->transmit_count));
		fprintf(fd, "#\n");
		flags = rte_atomic32_read(&info->port_flags);
		fprintf(fd,
		        "# Port: %2d, Burst:%3d, Rate:%3d%%, Flags:%08x, TX Count:%s\n",
		        info->pid,
		        info->tx_burst,
		        info->tx_rate,
		        flags,
		        buff);
		fprintf(fd, "#           SeqCnt:%d, Prime:%d VLAN ID:%04x, ",
		        info->seqCnt, info->prime_cnt, info->vlanid);
		pktgen_link_state(info->pid, buff, sizeof(buff));
		fprintf(fd, "Link: %s\n", buff);

		fprintf(fd, "#\n# Set up the primary port information:\n");
		fprintf(fd, "set %d count %ld\n", info->pid,
		        rte_atomic64_read(&info->transmit_count));
		fprintf(fd,
		        "set %d size %d\n",
		        info->pid,
		        pkt->pktSize + FCS_SIZE);
		fprintf(fd, "set %d rate %d\n", info->pid, info->tx_rate);
		fprintf(fd, "set %d burst %d\n", info->pid, info->tx_burst);
		fprintf(fd, "set %d sport %d\n", info->pid, pkt->sport);
		fprintf(fd, "set %d dport %d\n", info->pid, pkt->dport);
		fprintf(fd, "set %d prime %d\n", info->pid, info->prime_cnt);
		fprintf(fd, "type %s %d\n",
		        (pkt->ethType == ETHER_TYPE_IPv4) ? "ipv4" :
		        (pkt->ethType == ETHER_TYPE_IPv6) ? "ipv6" :
		        (pkt->ethType == ETHER_TYPE_VLAN) ? "vlan" :
		        (pkt->ethType == ETHER_TYPE_ARP) ? "arp" : "unknown",
		        i);
		fprintf(fd, "proto %s %d\n",
		        (pkt->ipProto == PG_IPPROTO_TCP) ? "tcp" :
		        (pkt->ipProto == PG_IPPROTO_ICMP) ? "icmp" : "udp", i);
		fprintf(fd, "set ip dst %d %s\n", i,
		        inet_ntop4(buff, sizeof(buff), ntohl(pkt->ip_dst_addr.addr.ipv4.s_addr),
		                   0xFFFFFFFF));
		fprintf(fd, "set ip src %d %s\n", i,
		        inet_ntop4(buff, sizeof(buff), ntohl(pkt->ip_src_addr.addr.ipv4.s_addr),
		                   pkt->ip_mask));
		fprintf(fd, "set mac %d %s\n", info->pid,
		        inet_mtoa(buff, sizeof(buff), &pkt->eth_dst_addr));
		fprintf(fd, "vlanid %d %d\n\n", i, pkt->vlanid);

		fprintf(fd,
		        "pattern %d %s\n",
		        i,
		        (info->fill_pattern_type == ABC_FILL_PATTERN) ? "abc" :
		        (info->fill_pattern_type == NO_FILL_PATTERN) ? "none" :
		        (info->fill_pattern_type ==
		         ZERO_FILL_PATTERN) ? "zero" : "user");
		if (strlen(info->user_pattern) )
			fprintf(fd,
			        "user.pattern %d %s\n",
			        i,
			        info->user_pattern);
		fprintf(fd, "\n");

		fprintf(fd,
		        "latency %d %s\n",
		        i,
		        (flags & SEND_LATENCY_PKTS) ? "enable" : "disable");

		fprintf(fd,
		        "mpls %d %sable\n",
		        i,
		        (flags & SEND_MPLS_LABEL) ? "en" : "dis");
		sprintf(buff, "%x", pkt->mpls_entry);
		fprintf(fd, "mpls_entry %d %s\n", i, buff);

		fprintf(fd,
		        "qinq %d %sable\n",
		        i,
		        (flags & SEND_Q_IN_Q_IDS) ? "en" : "dis");
		fprintf(fd,
		        "qinqids %d %d %d\n",
		        i,
		        pkt->qinq_outerid,
		        pkt->qinq_innerid);

		fprintf(fd,
		        "gre %d %sable\n",
		        i,
		        (flags & SEND_GRE_IPv4_HEADER) ? "en" : "dis");
		fprintf(fd, "gre_eth %d %sable\n", i,
		        (flags & SEND_GRE_ETHER_HEADER) ? "en" : "dis");
		fprintf(fd, "gre_key %d %d\n", i, pkt->gre_key);

		fprintf(fd, "#\n# Port flag values:\n");
		fprintf(fd, "icmp.echo %d %sable\n", i,
		        (flags & ICMP_ECHO_ENABLE_FLAG) ? "en" : "dis");
		fprintf(fd,
		        "pcap %d %sable\n",
		        i,
		        (flags & SEND_PCAP_PKTS) ? "en" : "dis");
		fprintf(fd,
		        "range %d %sable\n",
		        i,
		        (flags & SEND_RANGE_PKTS) ? "en" : "dis");
		fprintf(fd, "process %d %sable\n", i,
		        (flags & PROCESS_INPUT_PKTS) ? "en" : "dis");
		fprintf(fd,
		        "capture %d %sable\n",
		        i,
		        (flags & CAPTURE_PKTS) ? "en" : "dis");
		fprintf(fd,
		        "rxtap %d %sable\n",
		        i,
		        (flags & PROCESS_RX_TAP_PKTS) ? "en" : "dis");
		fprintf(fd,
		        "txtap %d %sable\n",
		        i,
		        (flags & PROCESS_TX_TAP_PKTS) ? "en" : "dis");
		fprintf(fd,
		        "vlan %d %sable\n\n",
		        i,
		        (flags & SEND_VLAN_ID) ? "en" : "dis");

		fprintf(fd, "#\n# Range packet information:\n");
		fprintf(fd, "src.mac start %d %s\n", i,
		        inet_mtoa(buff, sizeof(buff),
		                  inet_h64tom(range->src_mac, &eaddr)));
		fprintf(fd, "src.mac min %d %s\n", i,
		        inet_mtoa(buff, sizeof(buff),
		                  inet_h64tom(range->src_mac_min, &eaddr)));
		fprintf(fd, "src.mac max %d %s\n", i,
		        inet_mtoa(buff, sizeof(buff),
		                  inet_h64tom(range->src_mac_max, &eaddr)));
		fprintf(fd, "src.mac inc %d %s\n", i,
		        inet_mtoa(buff, sizeof(buff),
		                  inet_h64tom(range->src_mac_inc, &eaddr)));

		fprintf(fd, "dst.mac start %d %s\n", i,
		        inet_mtoa(buff, sizeof(buff),
		                  inet_h64tom(range->dst_mac, &eaddr)));
		fprintf(fd, "dst.mac min %d %s\n", i,
		        inet_mtoa(buff, sizeof(buff),
		                  inet_h64tom(range->dst_mac_min, &eaddr)));
		fprintf(fd, "dst.mac max %d %s\n", i,
		        inet_mtoa(buff, sizeof(buff),
		                  inet_h64tom(range->dst_mac_max, &eaddr)));
		fprintf(fd, "dst.mac inc %d %s\n", i,
		        inet_mtoa(buff, sizeof(buff),
		                  inet_h64tom(range->dst_mac_inc, &eaddr)));

		fprintf(fd, "\n");
		fprintf(fd, "src.ip start %d %s\n", i,
		        inet_ntop4(buff, sizeof(buff), ntohl(range->src_ip),
		                   0xFFFFFFFF));
		fprintf(fd, "src.ip min %d %s\n", i,
		        inet_ntop4(buff, sizeof(buff), ntohl(range->src_ip_min),
		                   0xFFFFFFFF));
		fprintf(fd, "src.ip max %d %s\n", i,
		        inet_ntop4(buff, sizeof(buff), ntohl(range->src_ip_max),
		                   0xFFFFFFFF));
		fprintf(fd, "src.ip inc %d %s\n", i,
		        inet_ntop4(buff, sizeof(buff), ntohl(range->src_ip_inc),
		                   0xFFFFFFFF));

		fprintf(fd, "\n");
		fprintf(fd, "dst.ip start %d %s\n", i,
		        inet_ntop4(buff, sizeof(buff), ntohl(range->dst_ip),
		                   0xFFFFFFFF));
		fprintf(fd, "dst.ip min %d %s\n", i,
		        inet_ntop4(buff, sizeof(buff), ntohl(range->dst_ip_min),
		                   0xFFFFFFFF));
		fprintf(fd, "dst.ip max %d %s\n", i,
		        inet_ntop4(buff, sizeof(buff), ntohl(range->dst_ip_max),
		                   0xFFFFFFFF));
		fprintf(fd, "dst.ip inc %d %s\n", i,
		        inet_ntop4(buff, sizeof(buff), ntohl(range->dst_ip_inc),
		                   0xFFFFFFFF));

		fprintf(fd, "\n");
		fprintf(fd, "ip.proto %d %s\n", i,
			(range->ip_proto == PG_IPPROTO_UDP)? "udp" :
			(range->ip_proto == PG_IPPROTO_ICMP)? "icmp" : "tcp");

		fprintf(fd, "\n");
		fprintf(fd, "src.port start %d %d\n", i, range->src_port);
		fprintf(fd, "src.port min %d %d\n", i, range->src_port_min);
		fprintf(fd, "src.port max %d %d\n", i, range->src_port_max);
		fprintf(fd, "src.port inc %d %d\n", i, range->src_port_inc);

		fprintf(fd, "\n");
		fprintf(fd, "dst.port start %d %d\n", i, range->dst_port);
		fprintf(fd, "dst.port min %d %d\n", i, range->dst_port_min);
		fprintf(fd, "dst.port max %d %d\n", i, range->dst_port_max);
		fprintf(fd, "dst.port inc %d %d\n", i, range->dst_port_inc);

		fprintf(fd, "\n");
		fprintf(fd, "vlan.id start %d %d\n", i, range->vlan_id);
		fprintf(fd, "vlan.id min %d %d\n", i, range->vlan_id_min);
		fprintf(fd, "vlan.id max %d %d\n", i, range->vlan_id_max);
		fprintf(fd, "vlan.id inc %d %d\n", i, range->vlan_id_inc);

		fprintf(fd, "\n");
		fprintf(fd,
		        "pkt.size start %d %d\n",
		        i,
		        range->pkt_size + FCS_SIZE);
		fprintf(fd,
		        "pkt.size min %d %d\n",
		        i,
		        range->pkt_size_min + FCS_SIZE);
		fprintf(fd,
		        "pkt.size max %d %d\n",
		        i,
		        range->pkt_size_max + FCS_SIZE);
		fprintf(fd, "pkt.size inc %d %d\n\n", i, range->pkt_size_inc);

		fprintf(fd, "#\n# Set up the sequence data for the port.\n");
		fprintf(fd, "set %d seqCnt %d\n", info->pid, info->seqCnt);
		for (j = 0; j < info->seqCnt; j++) {
			pkt = &info->seq_pkt[j];
			fprintf(fd, "seq %d %d %s ", j, i,
			        inet_mtoa(buff,
			                  sizeof(buff),
			                  &pkt->eth_dst_addr));
			fprintf(fd, "%s ",
			        inet_mtoa(buff,
			                  sizeof(buff),
			                  &pkt->eth_src_addr));
			fprintf(fd, "%s ",
			        inet_ntop4(buff, sizeof(buff),
			                   htonl(pkt->ip_dst_addr.addr.ipv4.s_addr),
			                   0xFFFFFFFF));
			fprintf(fd, "%s ",
			        inet_ntop4(buff, sizeof(buff),
			                   htonl(pkt->ip_src_addr.addr.ipv4.s_addr),
			                   pkt->ip_mask));
			fprintf(fd,
			        "%d %d %s %s %d %d\n",
			        pkt->sport,
			        pkt->dport,
			        (pkt->ethType == ETHER_TYPE_IPv4) ? "ipv4" :
			        (pkt->ethType == ETHER_TYPE_IPv6) ? "ipv6" :
			        (pkt->ethType == ETHER_TYPE_VLAN) ? "vlan" : "Other",
			        (pkt->ipProto == PG_IPPROTO_TCP) ? "tcp" :
			        (pkt->ipProto == PG_IPPROTO_ICMP) ? "icmp" : "udp",
			        pkt->vlanid,
			        pkt->pktSize + FCS_SIZE);
		}

		if (pktgen.info[i].pcap) {
			fprintf(fd, "#\n# PCAP port %d\n", i);
			fprintf(fd,
			        "#    Packet count: %d\n",
			        pktgen.info[i].pcap->pkt_count);
			fprintf(fd,
			        "#    Filename    : %s\n",
			        pktgen.info[i].pcap->filename);
		}
		fprintf(fd, "\n");
	}
	fprintf(fd,
	        "################################ Done #################################\n");

	fclose(fd);
	return 0;
}

/**************************************************************************//**
 *
 * pktgen_port_transmitting - Is the port transmitting packets?
 *
 * DESCRIPTION
 * Is the port transmitting packets.
 *
 * RETURNS: 1 for yes and 0 for no.
 *
 * SEE ALSO:
 */

int
pktgen_port_transmitting(int port)
{
	return rte_atomic32_read(&pktgen.info[port].port_flags) &
	       SENDING_PACKETS;
}

/**************************************************************************//**
 *
 * pktgen_link_state - Get the ASCII string for the port state.
 *
 * DESCRIPTION
 * Return the port state string for a given port.
 *
 * RETURNS: String pointer to link state
 *
 * SEE ALSO:
 */

char *
pktgen_link_state(int port, char *buff, int len)
{
	port_info_t *info = &pktgen.info[port];

	if (info->link.link_status)
		snprintf(buff, len, "<UP-%u-%s>",
		         (uint32_t)info->link.link_speed,
		         (info->link.link_duplex ==
		          ETH_LINK_FULL_DUPLEX) ? ("FD") : ("HD"));
	else
		snprintf(buff, len, "<--Down-->");

	return buff;
}

/**************************************************************************//**
 *
 * pktgen_transmit_count_rate - Get a string for the current transmit count and rate
 *
 * DESCRIPTION
 * Current value of the transmit count/%rate as a string.
 *
 * RETURNS: String pointer to transmit count/%rate.
 *
 * SEE ALSO:
 */

char *
pktgen_transmit_count_rate(int port, char *buff, int len)
{
	port_info_t *info = &pktgen.info[port];

	if (rte_atomic64_read(&info->transmit_count) == 0)
		snprintf(buff, len, "Forever /%4d%%", info->tx_rate);
	else
		snprintf(buff, len, "%ld /%4d%%",
		         rte_atomic64_read(&info->transmit_count),
		         info->tx_rate);

	return buff;
}

/**************************************************************************//**
 *
 * pktgen_port_sizes - Current stats for all port sizes
 *
 * DESCRIPTION
 * Structure returned with all of the counts for each port size.
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

int
pktgen_port_sizes(int port, port_sizes_t *psizes)
{
	port_info_t *info = &pktgen.info[port];

	*psizes = info->sizes;
	return 0;
}

/**************************************************************************//**
 *
 * pktgen_pkt_stats - Get the packet stats structure.
 *
 * DESCRIPTION
 * Return the packet statistics values.
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

int
pktgen_pkt_stats(int port, pkt_stats_t *pstats)
{
	port_info_t *info = &pktgen.info[port];

	*pstats = info->stats;
	return 0;
}

/**************************************************************************//**
 *
 * pktgen_port_stats - Get the port or rate stats for a given port
 *
 * DESCRIPTION
 * Get the ports or rate stats from a given port.
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

int
pktgen_port_stats(int port, const char *name, eth_stats_t *pstats)
{
	port_info_t *info = &pktgen.info[port];

	if (strcmp(name, "port") == 0)
		*pstats = info->port_stats;
	else if (strcmp(name, "rate") == 0)
		*pstats = info->rate_stats;

	return 0;
}

/**************************************************************************//**
 *
 * pktgen_flags_string - Return the flags string for display
 *
 * DESCRIPTION
 * Return the current flags string for display for a port.
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

char *
pktgen_flags_string(port_info_t *info)
{
	static char buff[32];
	uint32_t flags = rte_atomic32_read(&info->port_flags);

	snprintf(buff, sizeof(buff), "%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c",
	         (pktgen.flags & PROMISCUOUS_ON_FLAG) ? 'P' : '-',
	         (flags & ICMP_ECHO_ENABLE_FLAG) ? 'E' : '-',
	         (flags & SEND_ARP_REQUEST) ? 'A' : '-',
	         (flags & SEND_GRATUITOUS_ARP) ? 'G' : '-',
	         (flags & SEND_PCAP_PKTS) ? 'p' : '-',
	         (flags & SEND_SEQ_PKTS) ? 'S' : '-',
	         (flags & SEND_RANGE_PKTS) ? 'R' : '-',
	         (flags & PROCESS_INPUT_PKTS) ? 'I' : '-',
	         "-rt*"[(flags & (PROCESS_RX_TAP_PKTS | PROCESS_TX_TAP_PKTS)) >>
	                9],
	         (flags & SEND_LATENCY_PKTS) ? 'L' : '-',
	         (flags & SEND_VLAN_ID) ? 'V' :
	         (flags & SEND_MPLS_LABEL) ? 'M' :
	         (flags & SEND_Q_IN_Q_IDS) ? 'Q' : '-',
	         (flags & PROCESS_GARP_PKTS) ? 'g' : '-',
	         (flags & SEND_GRE_IPv4_HEADER) ? 'g' :
	         (flags & SEND_GRE_ETHER_HEADER) ? 'G' : '-',
	         (flags & CAPTURE_PKTS) ? 'C' : '-',
	         (flags & SEND_RANDOM_PKTS) ? 'R' : '-');

	return buff;
}

/**************************************************************************//**
 *
 * pktgen_redisplay - Redisplay the screen or clear the screen.
 *
 * DESCRIPTION
 * Redisplay the screen or clear the screen based on flag.
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

void
pktgen_redisplay(int cls_flag)
{
	if (wr_scrn_is_paused() )
		return;

	wr_scrn_pause();
	if (cls_flag) {
		wr_scrn_cls();
		wr_scrn_pos(100, 1);
	}
	pktgen.flags |= PRINT_LABELS_FLAG;
	wr_scrn_resume();

	pktgen_page_display(NULL, NULL);
}

/**************************************************************************//**
 *
 * pktgen_update_display - Update the display, but do not clear screen.
 *
 * DESCRIPTION
 * Update the display, but do not clear the screen.
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

void
pktgen_update_display(void)
{
	pktgen_redisplay(0);
}

/**************************************************************************//**
 *
 * pktgen_set_page_size - Set the number of ports per page.
 *
 * DESCRIPTION
 * Set the max number of ports per page.
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

void
pktgen_set_page_size(uint32_t page_size)
{
	if ( (page_size > 0) && (page_size <= pktgen.nb_ports) &&
	     (page_size <= 6) ) {
		pktgen.nb_ports_per_page = page_size;
		pktgen.ending_port = pktgen.starting_port + page_size;
		if (pktgen.ending_port >=
		    (pktgen.starting_port + pktgen.nb_ports) )
			pktgen.ending_port =
			        (pktgen.starting_port + pktgen.nb_ports);
		pktgen_redisplay(1);
	}
}

/**************************************************************************//**
 *
 * pktgen_screen - Enable or Disable screen updates.
 *
 * DESCRIPTION
 * Enable or disable screen updates.
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

void
pktgen_screen(const char *onOff)
{
	uint16_t rows;

	pktgen_display_get_geometry(&rows, NULL);

	if (parseState(onOff) == DISABLE_STATE) {
		if (!wr_scrn_is_paused() ) {
			wr_scrn_pause();
			wr_scrn_cls();
			wr_scrn_setw(1);
			wr_scrn_pos(100, 1);
		}
	} else {
		wr_scrn_cls();
		wr_scrn_pos(100, 1);
		wr_scrn_setw(pktgen.last_row + 1);
		wr_scrn_resume();
		pktgen_redisplay(1);
	}
}

/**************************************************************************//**
 *
 * pktgen_set_port_number - Set the current port number for sequence and range pages
 *
 * DESCRIPTION
 * Set the current port number for sequence and range pages.
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

void
pktgen_set_port_number(uint32_t port_number)
{
	if (port_number <= pktgen.nb_ports) {
		pktgen.portNum = port_number;
		pktgen_redisplay(1);
	}
}

/**************************************************************************//**
 *
 * pktgen_set_icmp_echo - Set the ICMP echo response flag on a port
 *
 * DESCRIPTION
 * Enable or disable the ICMP echo response flags for the given ports.
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

void
pktgen_set_icmp_echo(port_info_t *info, uint32_t onOff)
{
	if (onOff == ENABLE_STATE)
		pktgen_set_port_flags(info, ICMP_ECHO_ENABLE_FLAG);
	else
		pktgen_clr_port_flags(info, ICMP_ECHO_ENABLE_FLAG);
}

/**************************************************************************//**
 *
 * pktgen_set_rx_tap - Enable or disable the Rx TAP interface
 *
 * DESCRIPTION
 * Create and setup the Rx TAP interface.
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

void
pktgen_set_rx_tap(port_info_t *info, uint32_t onOff)
{
	if (onOff == ENABLE_STATE) {
		struct ifreq ifr;
		int sockfd, i;
		static const char *tapdevs[] =
		{ "/dev/net/tun", "/dev/tun", NULL };

		for (i = 0; tapdevs[i]; i++)
			if ( (info->rx_tapfd = open(tapdevs[i], O_RDWR)) >= 0)
				break;
		if (tapdevs[i] == NULL) {
			pktgen_log_error("Unable to create TUN/TAP interface");
			return;
		}
		memset(&ifr, 0, sizeof(struct ifreq));

		ifr.ifr_flags = IFF_TAP | IFF_NO_PI;

		snprintf(ifr.ifr_name, IFNAMSIZ, "%s%d", "pg_rxtap", info->pid);
		if (ioctl(info->rx_tapfd, TUNSETIFF, (void *)&ifr) < 0) {
			pktgen_log_error("Unable to set TUNSETIFF for %s",
			                 ifr.ifr_name);
			close(info->rx_tapfd);
			info->rx_tapfd = 0;
			return;
		}

		sockfd = socket(AF_INET, SOCK_DGRAM, 0);

		ifr.ifr_flags = IFF_UP | IFF_RUNNING;
		if (ioctl(sockfd, SIOCSIFFLAGS, (void *)&ifr) < 0) {
			pktgen_log_error("Unable to set SIOCSIFFLAGS for %s",
			                 ifr.ifr_name);
			close(sockfd);
			close(info->rx_tapfd);
			info->rx_tapfd = 0;
			return;
		}
		close(sockfd);
		pktgen_set_port_flags(info, PROCESS_RX_TAP_PKTS);
	} else {
		if (rte_atomic32_read(&info->port_flags) &
		    PROCESS_RX_TAP_PKTS) {
			close(info->rx_tapfd);
			info->rx_tapfd = 0;
		}
		pktgen_clr_port_flags(info, PROCESS_RX_TAP_PKTS);
	}
}

/**************************************************************************//**
 *
 * pktgen_set_tx_tap - Enable or disable the Tx TAP interface
 *
 * DESCRIPTION
 * Create and setup the Tx TAP interface.
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

void
pktgen_set_tx_tap(port_info_t *info, uint32_t onOff)
{
	if (onOff == ENABLE_STATE) {
		struct ifreq ifr;
		int sockfd, i;
		static const char *tapdevs[] =
		{ "/dev/net/tun", "/dev/tun", NULL };

		for (i = 0; tapdevs[i]; i++)
			if ( (info->tx_tapfd = open(tapdevs[i], O_RDWR)) >= 0)
				break;
		if (tapdevs[i] == NULL) {
			pktgen_log_error("Unable to create TUN/TAP interface.");
			return;
		}
		memset(&ifr, 0, sizeof(struct ifreq));

		ifr.ifr_flags = IFF_TAP | IFF_NO_PI;

		snprintf(ifr.ifr_name, IFNAMSIZ, "%s%d", "pg_txtap", info->pid);
		if (ioctl(info->tx_tapfd, TUNSETIFF, (void *)&ifr) < 0) {
			pktgen_log_error("Unable to set TUNSETIFF for %s",
			                 ifr.ifr_name);
			close(info->tx_tapfd);
			info->tx_tapfd = 0;
			return;
		}

		sockfd = socket(AF_INET, SOCK_DGRAM, 0);

		ifr.ifr_flags = IFF_UP | IFF_RUNNING;
		if (ioctl(sockfd, SIOCSIFFLAGS, (void *)&ifr) < 0) {
			pktgen_log_error("Unable to set SIOCSIFFLAGS for %s",
			                 ifr.ifr_name);
			close(sockfd);
			close(info->tx_tapfd);
			info->tx_tapfd = 0;
			return;
		}
		close(sockfd);
		pktgen_set_port_flags(info, PROCESS_TX_TAP_PKTS);
	} else {
		if (rte_atomic32_read(&info->port_flags) &
		    PROCESS_TX_TAP_PKTS) {
			close(info->tx_tapfd);
			info->tx_tapfd = 0;
		}
		pktgen_clr_port_flags(info, PROCESS_TX_TAP_PKTS);
	}
}

/**************************************************************************//**
 *
 * pktgen_mac_from_arp - Enable or disable getting MAC from ARP requests.
 *
 * DESCRIPTION
 * Enable or disable getting the MAC address from the ARP request packets.
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

void
pktgen_mac_from_arp(uint32_t onOff)
{
	if (onOff == ENABLE_STATE)
		pktgen.flags |= MAC_FROM_ARP_FLAG;
	else
		pktgen.flags &= ~MAC_FROM_ARP_FLAG;
}

/**************************************************************************//**
 *
 * pktgen_set_random - Enable/disable random bitfield mode
 *
 * DESCRIPTION
 * Enable/disable random bitfield mode
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

void
pktgen_set_random(port_info_t *info, uint32_t onOff)
{
	if (onOff == ENABLE_STATE)
		pktgen_set_port_flags(info, SEND_RANDOM_PKTS);
	else
		pktgen_clr_port_flags(info, SEND_RANDOM_PKTS);
}

/*
 * Local wrapper function to test mp is NULL and return or continue
 * to call rte_mempool_dump() routine.
 */
static void
__mempool_dump(FILE *f, struct rte_mempool *mp) {
	if (mp == NULL)
		return;
	rte_mempool_dump(f, mp);
}

/**************************************************************************//**
 *
 * pktgen_mempool_dump - Display the mempool information
 *
 * DESCRIPTION
 * Dump out the mempool information.
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

void
pktgen_mempool_dump(port_info_t *info, char *name)
{
	int all;
	uint16_t q;

	all = !strcmp(name, "all");

	if (info->q[0].tx_mp == NULL)
		return;

	for (q = 0; q < wr_get_port_rxcnt(pktgen.l2p, info->pid); q++)
		if (all || !strcmp(name, "rx") )
			rte_mempool_dump(stdout, info->q[q].rx_mp);
	for (q = 0; q < wr_get_port_txcnt(pktgen.l2p, info->pid); q++) {
		if (all ||
		    (!strcmp(name,
		             "tx") &&
		     (q < wr_get_port_txcnt(pktgen.l2p, info->pid))) )
			__mempool_dump(stdout, info->q[q].tx_mp);
		if (all || !strcmp(name, "range") )
			__mempool_dump(stdout, info->q[q].range_mp);
		if (all || !strcmp(name, "seq") )
			__mempool_dump(stdout, info->q[q].seq_mp);
		if (all || !strcmp(name, "arp") )
			__mempool_dump(stdout, info->q[q].special_mp);
		if (all || !strcmp(name, "pcap") )
			__mempool_dump(stdout, info->q[q].pcap_mp);
	}
}

/**************************************************************************//**
 *
 * pktgen_start_transmitting - Start a port transmitting packets.
 *
 * DESCRIPTION
 * Start the given ports sending packets.
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

void
pktgen_start_transmitting(port_info_t *info)
{
	uint8_t q;

	if (!(rte_atomic32_read(&info->port_flags) & SENDING_PACKETS) ) {
		for (q = 0; q < wr_get_port_txcnt(pktgen.l2p, info->pid); q++)
			pktgen_set_q_flags(info, q, CLEAR_FAST_ALLOC_FLAG);

		rte_atomic64_set(&info->current_tx_count,
		                 rte_atomic64_read(&info->transmit_count));

		pktgen_set_port_flags(info, SENDING_PACKETS);

		if (rte_atomic64_read(&info->current_tx_count) == 0)
			pktgen_set_port_flags(info, SEND_FOREVER);
	}
}

/**************************************************************************//**
 *
 * pktgen_stop_transmitting - Stop port transmitting packets.
 *
 * DESCRIPTION
 * Stop the given ports from sending traffic.
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

void
pktgen_stop_transmitting(port_info_t *info)
{
	uint8_t q;

	if (rte_atomic32_read(&info->port_flags) & SENDING_PACKETS) {
		pktgen_clr_port_flags(info, (SENDING_PACKETS | SEND_FOREVER));
		for (q = 0; q < wr_get_port_txcnt(pktgen.l2p, info->pid); q++)
			pktgen_set_q_flags(info, q, DO_TX_FLUSH);
	}
}

/**************************************************************************//**
 *
 * pktgen_prime_ports - Send a small number of packets to setup forwarding tables
 *
 * DESCRIPTION
 * Send a small number of packets from a port to setup the forwarding tables in
 * the device under test.
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

void
pktgen_prime_ports(port_info_t *info)
{
	uint8_t q;

	for (q = 0; q < wr_get_port_txcnt(pktgen.l2p, info->pid); q++)
		pktgen_set_q_flags(info, q, CLEAR_FAST_ALLOC_FLAG);
	rte_atomic64_set(&info->current_tx_count, info->prime_cnt);
	pktgen_set_port_flags(info, SENDING_PACKETS);
	rte_delay_ms(300);
	for (q = 0; q < wr_get_port_txcnt(pktgen.l2p, info->pid); q++)
		pktgen_set_q_flags(info, q, DO_TX_FLUSH);
}

/**************************************************************************//**
 *
 * pktgen_set_proto - Set up the protocol type for a port/packet.
 *
 * DESCRIPTION
 * Setup all single packets with a protocol types with the port list.
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

void
pktgen_set_proto(port_info_t *info, char type)
{
	info->seq_pkt[SINGLE_PKT].ipProto = (type == 'u') ? PG_IPPROTO_UDP :
	        (type == 'i') ? PG_IPPROTO_ICMP :
	        (type == 't') ? PG_IPPROTO_TCP :
		/* TODO print error: unknown type */ PG_IPPROTO_TCP;

	/* ICMP only works on IPv4 packets. */
	if (type == 'i')
		info->seq_pkt[SINGLE_PKT].ethType = ETHER_TYPE_IPv4;

	pktgen_packet_ctor(info, SINGLE_PKT, -1);
}

/**************************************************************************//**
 *
 * pktgen_set_proto_range - Set up the protocol type for a port/packet.
 *
 * DESCRIPTION
 * Setup all range packets with a protocol types with the port list.
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

void
pktgen_set_proto_range(port_info_t *info, char type)
{
	info->seq_pkt[RANGE_PKT].ipProto = (type == 'u') ? PG_IPPROTO_UDP :
	        (type == 'i') ? PG_IPPROTO_ICMP :
	        (type == 't') ? PG_IPPROTO_TCP :
		/* TODO print error: unknown type */ PG_IPPROTO_TCP;
	info->range.ip_proto = info->seq_pkt[RANGE_PKT].ipProto;

	/* ICMP only works on IPv4 packets. */
	if (type == 'i')
		info->seq_pkt[RANGE_PKT].ethType = ETHER_TYPE_IPv4;
}

/**************************************************************************//**
 *
 * pktgen_pcap_enable_disable - Enable or disable PCAP sending of packets.
 *
 * DESCRIPTION
 * Enable or disable PCAP packet sending.
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

void
pktgen_pcap_enable_disable(port_info_t *info, char *str)
{
	if ( (info->pcap != NULL) && (info->pcap->pkt_count != 0) ) {
		if (parseState(str) == ENABLE_STATE) {
			pktgen_clr_port_flags(info, SEND_RANGE_PKTS);
			pktgen_clr_port_flags(info, SEND_SEQ_PKTS);
			pktgen_set_port_flags(info, SEND_PCAP_PKTS);
		} else
			pktgen_clr_port_flags(info, SEND_PCAP_PKTS);
		pktgen_packet_rate(info);
	}
}

/**************************************************************************//**
 *
 * pktgen_pcap_filter - Compile a PCAP filter for a portlist
 *
 * DESCRIPTION
 * Compile a pcap filter for a portlist
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

void
pktgen_pcap_filter(port_info_t *info, char *str)
{
	pcap_t *pc = pcap_open_dead(DLT_EN10MB, 65535);

	info->pcap_result = pcap_compile(pc,
	                                 &info->pcap_program,
	                                 str,
	                                 1,
	                                 PCAP_NETMASK_UNKNOWN);

	pcap_close(pc);
}

/**************************************************************************//**
 *
 * pktgen_blink_enable_disable - Enable or disable a port from blinking.
 *
 * DESCRIPTION
 * Enable or disable the given ports from blinking.
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

void
pktgen_blink_enable_disable(port_info_t *info, char *str)
{
	if (parseState(str) == ENABLE_STATE)
		pktgen.blinklist |= (1 << info->pid);
	else {
		pktgen.blinklist &= ~(1 << info->pid);
		rte_eth_led_on(info->pid);
	}
}

/**************************************************************************//**
 *
 * pktgen_process_enable_disable - Enable or disable input packet processing.
 *
 * DESCRIPTION
 * Enable or disable input packet processing of ICMP, ARP, ...
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

void
pktgen_process_enable_disable(port_info_t *info, char *str)
{
	if (parseState(str) == ENABLE_STATE)
		pktgen_set_port_flags(info, PROCESS_INPUT_PKTS);
	else
		pktgen_clr_port_flags(info, PROCESS_INPUT_PKTS);
}

/**************************************************************************//**
 *
 * pktgen_garp_enable_disable - Enable or disable GARP packet processing.
 *
 * DESCRIPTION
 * Enable or disable GARP packet processing of ICMP, ARP, ...
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

void
pktgen_garp_enable_disable(port_info_t *info, char *str)
{
	if (parseState(str) == ENABLE_STATE)
		pktgen_set_port_flags(info,
		                      PROCESS_GARP_PKTS | PROCESS_INPUT_PKTS);
	else
		pktgen_clr_port_flags(info,
		                      PROCESS_GARP_PKTS | PROCESS_INPUT_PKTS);
}

/**************************************************************************//**
 *
 * pktgen_set_pkt_type_range - Set the packet type value for range packets.
 *
 * DESCRIPTION
 * Set the packet type value for the given port list.
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

void
pktgen_set_pkt_type_range(port_info_t *info, const char *type)
{
	info->seq_pkt[RANGE_PKT].ethType = (type[0] == 'a') ? ETHER_TYPE_ARP :
	        (type[3] == '4') ? ETHER_TYPE_IPv4 :
	        (type[3] == '6') ? ETHER_TYPE_IPv6 :
		/* TODO print error: unknown type */ ETHER_TYPE_IPv4;
}

/**************************************************************************//**
 *
 * pktgen_set_pkt_type - Set the packet type value.
 *
 * DESCRIPTION
 * Set the packet type value for the given port list.
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

void
pktgen_set_pkt_type(port_info_t *info, const char *type)
{
	info->seq_pkt[SINGLE_PKT].ethType = (type[0] == 'a') ? ETHER_TYPE_ARP  :
	        (type[3] == '4') ? ETHER_TYPE_IPv4 :
	        (type[3] == '6') ? ETHER_TYPE_IPv6 :
		/* TODO print error: unknown type */ ETHER_TYPE_IPv4;

	pktgen_packet_ctor(info, SINGLE_PKT, -1);
}

/**************************************************************************//**
 *
 * pktgen_set_vlan - Set the port to send a VLAN ID
 *
 * DESCRIPTION
 * Set the given port list to send VLAN ID packets.
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

void
pktgen_set_vlan(port_info_t *info, uint32_t onOff)
{
	if (onOff == ENABLE_STATE) {
		pktgen_clr_port_flags(info, SEND_MPLS_LABEL);
		pktgen_clr_port_flags(info, SEND_Q_IN_Q_IDS);
		pktgen_set_port_flags(info, SEND_VLAN_ID);
	} else
		pktgen_clr_port_flags(info, SEND_VLAN_ID);
	pktgen_packet_ctor(info, SINGLE_PKT, -1);
}

/**************************************************************************//**
 *
 * pktgen_set_vlanid - Set the port VLAN ID value
 *
 * DESCRIPTION
 * Set the given port list with the given VLAN ID.
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

void
pktgen_set_vlanid(port_info_t *info, uint16_t vlanid)
{
	info->vlanid = vlanid;
	info->seq_pkt[SINGLE_PKT].vlanid = info->vlanid;
	pktgen_packet_ctor(info, SINGLE_PKT, -1);
}

/**************************************************************************//**
 *
 * pktgen_set_mpls - Set the port to send a mpls ID
 *
 * DESCRIPTION
 * Set the given port list to send mpls ID packets.
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

void
pktgen_set_mpls(port_info_t *info, uint32_t onOff)
{
	if (onOff == ENABLE_STATE) {
		pktgen_clr_port_flags(info, SEND_VLAN_ID);
		pktgen_clr_port_flags(info, SEND_Q_IN_Q_IDS);
		pktgen_set_port_flags(info, SEND_MPLS_LABEL);
	} else
		pktgen_clr_port_flags(info, SEND_MPLS_LABEL);
	pktgen_packet_ctor(info, SINGLE_PKT, -1);
}

/**************************************************************************//**
 *
 * pktgen_set_mpls_entry - Set the port MPLS entry value
 *
 * DESCRIPTION
 * Set the given port list with the given MPLS entry.
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

void
pktgen_set_mpls_entry(port_info_t *info, uint32_t mpls_entry)
{
	info->mpls_entry = mpls_entry;
	info->seq_pkt[SINGLE_PKT].mpls_entry = info->mpls_entry;
	pktgen_packet_ctor(info, SINGLE_PKT, -1);
}

/**************************************************************************//**
 *
 * pktgen_set_qinq - Set the port to send a Q-in-Q header
 *
 * DESCRIPTION
 * Set the given port list to send Q-in-Q ID packets.
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

void
pktgen_set_qinq(port_info_t *info, uint32_t onOff)
{
	if (onOff == ENABLE_STATE) {
		pktgen_clr_port_flags(info, SEND_VLAN_ID);
		pktgen_clr_port_flags(info, SEND_MPLS_LABEL);
		pktgen_set_port_flags(info, SEND_Q_IN_Q_IDS);
	} else
		pktgen_clr_port_flags(info, SEND_Q_IN_Q_IDS);
	pktgen_packet_ctor(info, SINGLE_PKT, -1);
}

/**************************************************************************//**
 *
 * pktgen_set_qinqids - Set the port Q-in-Q ID values
 *
 * DESCRIPTION
 * Set the given port list with the given Q-in-Q ID's.
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

void
pktgen_set_qinqids(port_info_t *info, uint16_t outerid, uint16_t innerid)
{
	info->qinq_outerid = outerid;
	info->seq_pkt[SINGLE_PKT].qinq_outerid = info->qinq_outerid;
	info->qinq_innerid = innerid;
	info->seq_pkt[SINGLE_PKT].qinq_innerid = info->qinq_innerid;
	pktgen_packet_ctor(info, SINGLE_PKT, -1);
}

/**************************************************************************//**
 *
 * pktgen_set_gre - Set the port to send GRE with IPv4 payload
 *
 * DESCRIPTION
 * Set the given port list to send GRE with IPv4 payload
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

void
pktgen_set_gre(port_info_t *info, uint32_t onOff)
{
	if (onOff == ENABLE_STATE) {
		pktgen_clr_port_flags(info, SEND_GRE_ETHER_HEADER);
		pktgen_set_port_flags(info, SEND_GRE_IPv4_HEADER);
	} else
		pktgen_clr_port_flags(info, SEND_GRE_IPv4_HEADER);
	pktgen_packet_ctor(info, SINGLE_PKT, -1);
}

/**************************************************************************//**
 *
 * pktgen_set_gre_eth - Set the port to send GRE with Ethernet payload
 *
 * DESCRIPTION
 * Set the given port list to send GRE with Ethernet payload
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

void
pktgen_set_gre_eth(port_info_t *info, uint32_t onOff)
{
	if (onOff == ENABLE_STATE) {
		pktgen_clr_port_flags(info, SEND_GRE_IPv4_HEADER);
		pktgen_set_port_flags(info, SEND_GRE_ETHER_HEADER);
	} else
		pktgen_clr_port_flags(info, SEND_GRE_ETHER_HEADER);
	pktgen_packet_ctor(info, SINGLE_PKT, -1);
}

/**************************************************************************//**
 *
 * pktgen_set_gre_key - Set the port GRE key
 *
 * DESCRIPTION
 * Set the given port list with the given GRE key.
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

void
pktgen_set_gre_key(port_info_t *info, uint32_t gre_key)
{
	info->gre_key = gre_key;
	info->seq_pkt[SINGLE_PKT].gre_key = info->gre_key;
	pktgen_packet_ctor(info, SINGLE_PKT, -1);
}

/**************************************************************************//**
 *
 * pktgen_clear_stats - Clear a given port list of stats.
 *
 * DESCRIPTION
 * Clear the given port list of all statistics.
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

void
pktgen_clear_stats(port_info_t *info)
{
	memset(&info->sizes, 0, sizeof(port_sizes_t));
	memset(&info->port_stats, 0, sizeof(eth_stats_t));
	memset(&info->rate_stats, 0, sizeof(eth_stats_t));

	rte_eth_stats_get(info->pid, &info->init_stats);
    pktgen.max_total_ipackets   = 0;
    pktgen.max_total_opackets   = 0;
    info->max_ipackets          = 0;
    info->max_opackets          = 0;
	info->stats.dropped_pkts    = 0;
	info->stats.arp_pkts        = 0;
	info->stats.echo_pkts       = 0;
	info->stats.ip_pkts         = 0;
	info->stats.ipv6_pkts       = 0;
	info->stats.vlan_pkts       = 0;
	info->stats.unknown_pkts    = 0;
	info->stats.tx_failed       = 0;

	memset(&pktgen.cumm_rate_totals, 0, sizeof(eth_stats_t));

	pktgen_update_display();
}

/**************************************************************************//**
 *
 * pktgen_cls - Clear the screen.
 *
 * DESCRIPTION
 * Clear the screen and redisplay the data.
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

void
pktgen_cls(void)
{
	if (wr_scrn_is_paused() ) {
		wr_scrn_cls();
		wr_scrn_pos(100, 1);
	} else	/* Update the display quickly. */
		pktgen_redisplay(1);
}

/**************************************************************************//**
 *
 * pktgen_update - Update the screen information
 *
 * DESCRIPTION
 * Update the screen information
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

void
pktgen_update(void)
{
	pktgen_page_display(NULL, NULL);
}

/**************************************************************************//**
 *
 * pktgen_port_defaults - Set all ports back to the default values.
 *
 * DESCRIPTION
 * Reset the ports back to the defaults.
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

void
pktgen_port_defaults(uint32_t pid, uint8_t seq)
{
	port_info_t *info = &pktgen.info[pid];
	pkt_seq_t *pkt = &info->seq_pkt[seq];
	port_info_t *dst_info;

	pkt->pktSize            = MIN_PKT_SIZE;
	pkt->sport              = DEFAULT_SRC_PORT;
	pkt->dport              = DEFAULT_DST_PORT;
	pkt->ipProto            = PG_IPPROTO_TCP;
	pkt->ethType            = ETHER_TYPE_IPv4;
	pkt->vlanid             = DEFAULT_VLAN_ID;

	rte_atomic64_set(&info->transmit_count, DEFAULT_TX_COUNT);
	rte_atomic64_init(&info->current_tx_count);
	info->tx_rate           = DEFAULT_TX_RATE;
	info->tx_burst          = DEFAULT_PKT_BURST;
	info->vlanid            = DEFAULT_VLAN_ID;
	info->seqCnt            = 0;
	info->seqIdx            = 0;
	info->prime_cnt         = DEFAULT_PRIME_COUNT;
	info->delta             = 0;

	pktgen_packet_rate(info);

	pkt->ip_mask = DEFAULT_NETMASK;
	if ( (pid & 1) == 0) {
		pkt->ip_src_addr.addr.ipv4.s_addr = DEFAULT_IP_ADDR | (pid << 8) | 1;
		pkt->ip_dst_addr.addr.ipv4.s_addr = DEFAULT_IP_ADDR | ((pid + 1) << 8) | 1;
		dst_info = info + 1;
	} else {
		pkt->ip_src_addr.addr.ipv4.s_addr = DEFAULT_IP_ADDR | (pid << 8) | 1;
		pkt->ip_dst_addr.addr.ipv4.s_addr = DEFAULT_IP_ADDR | ((pid - 1) << 8) | 1;
		dst_info = info - 1;
	}

	if (dst_info->seq_pkt != NULL)
		ether_addr_copy(&dst_info->seq_pkt[SINGLE_PKT].eth_src_addr,
		                &pkt->eth_dst_addr);
	else
		memset(&pkt->eth_dst_addr, 0, sizeof(pkt->eth_dst_addr));

	pktgen_packet_ctor(info, seq, -1);

	pktgen.flags    |= PRINT_LABELS_FLAG;
}

/**************************************************************************//**
 *
 * pktgen_ping4 - Send a IPv4 ICMP echo request.
 *
 * DESCRIPTION
 * Send a IPv4 ICMP echo request packet.
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

void
pktgen_ping4(port_info_t *info)
{
	memcpy(&info->seq_pkt[PING_PKT],
	       &info->seq_pkt[SINGLE_PKT], sizeof(pkt_seq_t));
	info->seq_pkt[PING_PKT].ipProto = PG_IPPROTO_ICMP;
	pktgen_packet_ctor(info, PING_PKT, ICMP4_ECHO);
	pktgen_set_port_flags(info, SEND_PING4_REQUEST);
}

#ifdef INCLUDE_PING6
/**************************************************************************//**
 *
 * pktgen_ping6 - Send a IPv6 ICMP echo request packet.
 *
 * DESCRIPTION
 * Send a IPv6 ICMP echo request packet for the given ports.
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

void
pktgen_ping6(port_info_t *info)
{
	memcpy(&info->pkt[PING_PKT],
	       &info->pkt[SINGLE_PKT], sizeof(pkt_seq_t));
	info->pkt[PING_PKT].ipProto = PG_IPPROTO_ICMP;
	pktgen_packet_ctor(info, PING_PKT, ICMP6_ECHO);
	pktgen_set_port_flags(info, SEND_PING6_REQUEST);
}

#endif

/**************************************************************************//**
 *
 * pktgen_reset - Reset all ports to the default state
 *
 * DESCRIPTION
 * Reset all ports to the default state.
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

void
pktgen_reset(port_info_t *info)
{
	uint32_t s;

	if (info == NULL)
		info = &pktgen.info[0];

	pktgen_stop_transmitting(info);

	pktgen.flags &= ~MAC_FROM_ARP_FLAG;

	/* Make sure the port is active and enabled. */
	if (info->seq_pkt) {
		info->seq_pkt[SINGLE_PKT].pktSize = MIN_PKT_SIZE;

		for (s = 0; s < NUM_TOTAL_PKTS; s++)
			pktgen_port_defaults(info->pid, s);

		pktgen_range_setup(info);
		pktgen_clear_stats(info);
	}

	pktgen.flags &= ~PRINT_LABELS_FLAG;
	pktgen_update_display();
}

/**************************************************************************//**
 *
 * pktgen_port_restart - Reset all ports
 *
 * DESCRIPTION
 * Reset all ports
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

void
pktgen_port_restart(port_info_t *info)
{
	if (info == NULL)
		info = &pktgen.info[0];

	pktgen_stop_transmitting(info);

	rte_delay_ms(10);

	/* Stop and start the device to flush TX and RX buffers from the device rings. */
	rte_eth_dev_stop(info->pid);

	rte_delay_us(250);

	rte_eth_dev_start(info->pid);

	pktgen.flags &= ~PRINT_LABELS_FLAG;
	pktgen_update_display();
}

/**************************************************************************//**
 *
 * pktgen_set_tx_count - Set the number of packets to transmit on a port.
 *
 * DESCRIPTION
 * Set the transmit count for all ports in the list.
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

void
pktgen_set_tx_count(port_info_t *info, uint32_t cnt)
{
	rte_atomic64_set(&info->transmit_count, cnt);
}

/**************************************************************************//**
 *
 * pktgen_set_port_seqCnt - Set the sequence count for a port
 *
 * DESCRIPTION
 * Set a sequence count of packets for all ports in the list.
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

void
pktgen_set_port_seqCnt(port_info_t *info, uint32_t cnt)
{
	if (cnt > NUM_SEQ_PKTS)
		cnt = NUM_SEQ_PKTS;

	info->seqCnt = cnt;
	if (cnt) {
		pktgen_clr_port_flags(info, SEND_RANGE_PKTS);
		pktgen_clr_port_flags(info, SEND_PCAP_PKTS);
		pktgen_set_port_flags(info, SEND_SEQ_PKTS);
	} else
		pktgen_clr_port_flags(info, SEND_SEQ_PKTS);
	pktgen_packet_rate(info);
}

/**************************************************************************//**
 *
 * pktgen_set_port_prime - Set the number of packets to send on a prime command
 *
 * DESCRIPTION
 * Set the number packets to send on the prime command for all ports in list.
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

void
pktgen_set_port_prime(port_info_t *info, uint32_t cnt)
{
	if (cnt > MAX_PRIME_COUNT)
		cnt = MAX_PRIME_COUNT;
	else if (cnt == 0)
		cnt = DEFAULT_PRIME_COUNT;

	info->prime_cnt = cnt;
}

/**************************************************************************//**
 *
 * pktgen_set_port_dump - Set the number of received packets to dump to screen.
 *
 * DESCRIPTION
 * Set the number of received packets to dump to screen.
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

void
pktgen_set_port_dump(port_info_t *info, uint32_t cnt)
{
	int i;

	if (cnt > MAX_DUMP_PACKETS)
		cnt = MAX_DUMP_PACKETS;

	/* Prevent concurrency issues by setting the fields in this specific order */
	info->dump_count = 0;
	info->dump_tail  = 0;
	info->dump_head  = 0;

	for (i = 0; i < MAX_DUMP_PACKETS; ++i)
		if (info->dump_list->data != NULL) {
			rte_free(info->dump_list->data);
			info->dump_list->data = NULL;
		}

	info->dump_count = cnt;
}

/**************************************************************************//**
 *
 * pktgen_set_tx_burst - Set the transmit burst count.
 *
 * DESCRIPTION
 * Set the transmit burst count for all packets.
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

void
pktgen_set_tx_burst(port_info_t *info, uint32_t burst)
{
	if (burst == 0)
		burst = 1;
	else if (burst > DEFAULT_PKT_BURST)
		burst = DEFAULT_PKT_BURST;
	info->tx_burst = burst;
	pktgen_packet_rate(info);
}

/**************************************************************************//**
 *
 * pktgen_set_tx_cycles - Set the number of Transmit cycles to use.
 *
 * DESCRIPTION
 * Set the number of transmit cycles for the given port list.
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

void
pktgen_set_tx_cycles(port_info_t *info, uint32_t cycles)
{
	info->tx_cycles     = cycles;
}

/**************************************************************************//**
 *
 * pktgen_set_pkt_size - Set the size of the packets to send.
 *
 * DESCRIPTION
 * Set the pkt size for the single packet transmit.
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

void
pktgen_set_pkt_size(port_info_t *info, uint32_t size)
{
	if ( (size - FCS_SIZE) < MIN_PKT_SIZE)
		size = (MIN_PKT_SIZE + FCS_SIZE);
	else if ( (size - FCS_SIZE) > MAX_PKT_SIZE)
		size = MAX_PKT_SIZE + FCS_SIZE;
	info->seq_pkt[SINGLE_PKT].pktSize = (size - FCS_SIZE);
	pktgen_packet_ctor(info, SINGLE_PKT, -1);
	pktgen_packet_rate(info);
}

/**************************************************************************//**
 *
 * pktgen_set_port_value - Set the port value for single or sequence packets.
 *
 * DESCRIPTION
 * Set the port value for single or sequence packets for the ports listed.
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

void
pktgen_set_port_value(port_info_t *info, char type, uint32_t portValue)
{
	if (type == 'd')
		info->seq_pkt[SINGLE_PKT].dport = (uint16_t)portValue;
	else
		info->seq_pkt[SINGLE_PKT].sport = (uint16_t)portValue;
	pktgen_packet_ctor(info, SINGLE_PKT, -1);
}

/**************************************************************************//**
 *
 * pktgen_set_tx_rate - Set the transmit rate as a percent value.
 *
 * DESCRIPTION
 * Set the transmit rate as a percent value for all ports listed.
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

void
pktgen_set_tx_rate(port_info_t *info, uint32_t rate)
{
	if (rate == 0)
		rate = 1;
	else if (rate > 100)
		rate = 100;
	info->tx_rate = rate;
	pktgen_packet_rate(info);
}

/**************************************************************************//**
 *
 * pktgen_set_ipaddr - Set the IP address for all ports listed
 *
 * DESCRIPTION
 * Set an IP address for all ports listed in the call.
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

void
pktgen_set_ipaddr(port_info_t *info, char type, cmdline_ipaddr_t *ip)
{
	if (type == 's') {
		info->seq_pkt[SINGLE_PKT].ip_mask = size_to_mask(ip->prefixlen);
		info->seq_pkt[SINGLE_PKT].ip_src_addr.addr.ipv4.s_addr = ntohl(
		                ip->addr.ipv4.s_addr);
	} else
		info->seq_pkt[SINGLE_PKT].ip_dst_addr.addr.ipv4.s_addr = ntohl(
		                ip->addr.ipv4.s_addr);
	pktgen_packet_ctor(info, SINGLE_PKT, -1);
}

/**************************************************************************//**
 *
 * pktgen_set_dst_mac - Setup the destination MAC address
 *
 * DESCRIPTION
 * Set the destination MAC address for all ports given.
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

void
pktgen_set_dst_mac(port_info_t *info, cmdline_etheraddr_t *mac)
{
	memcpy(&info->seq_pkt[SINGLE_PKT].eth_dst_addr, mac->mac, 6);
	pktgen_packet_ctor(info, SINGLE_PKT, -1);
}

/**************************************************************************//**
 *
 * pktgen_range_enable_disable - Enable or disable range packet sending.
 *
 * DESCRIPTION
 * Enable or disable range packet sending.
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

void
pktgen_range_enable_disable(port_info_t *info, char *str)
{
	if (parseState(str) == ENABLE_STATE) {
		pktgen_clr_port_flags(info, SEND_SEQ_PKTS);
		pktgen_clr_port_flags(info, SEND_PCAP_PKTS);
		pktgen_set_port_flags(info, SEND_RANGE_PKTS);
	} else
		pktgen_clr_port_flags(info, SEND_RANGE_PKTS);
	pktgen_packet_rate(info);
}

/**************************************************************************//**
 *
 * pktgen_latency_enable_disable - Enable or disable latency testing.
 *
 * DESCRIPTION
 * Enable or disable latency testing.
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

void
pktgen_latency_enable_disable(port_info_t *info, char *str)
{
	if (parseState(str) == ENABLE_STATE)
		pktgen_set_port_flags(info, SEND_LATENCY_PKTS);
	else
		pktgen_clr_port_flags(info, SEND_LATENCY_PKTS);
}

/**************************************************************************//**
 *
 * pktgen_set_pattern_type - Set the pattern type per port.
 *
 * DESCRIPTION
 * Set the given pattern type.
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

void
pktgen_set_pattern_type(port_info_t *info, char *str)
{
	if (strncmp(str, "abc", 3) == 0)
		info->fill_pattern_type = ABC_FILL_PATTERN;
	else if (strncmp(str, "none", 4) == 0)
		info->fill_pattern_type = NO_FILL_PATTERN;
	else if (strncmp(str, "user", 4) == 0)
		info->fill_pattern_type = USER_FILL_PATTERN;
	else if (strncmp(str, "zero", 4) == 0)
		info->fill_pattern_type = ZERO_FILL_PATTERN;
}

/**************************************************************************//**
 *
 * pktgen_user_pattern_set - Set the user pattern string.
 *
 * DESCRIPTION
 * Set the given user pattern string.
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

void
pktgen_user_pattern_set(port_info_t *info, char *str)
{
	char copy[USER_PATTERN_SIZE + 1], *cp;

	memset(copy, 0, sizeof(copy));
	strcpy(copy, str);
	cp = &copy[0];
	if ( (cp[0] == '"') || (cp[0] == '\'') ) {
		cp[strlen(cp) - 1] = 0;
		cp++;
	}
	memset(info->user_pattern, 0, USER_PATTERN_SIZE);
	strncpy(info->user_pattern, cp, USER_PATTERN_SIZE);
	info->fill_pattern_type = USER_FILL_PATTERN;
}

/**************************************************************************//**
 *
 * pktgen_set_dest_mac - Set the destination MAC address
 *
 * DESCRIPTION
 * Set the destination MAC address for all ports given.
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

void
pktgen_set_dest_mac(port_info_t *info,
                    const char *what,
                    cmdline_etheraddr_t *mac)
{
	if (!strcmp(what, "min") )
		inet_mtoh64((struct ether_addr *)mac, &info->range.dst_mac_min);
	else if (!strcmp(what, "max") )
		inet_mtoh64((struct ether_addr *)mac, &info->range.dst_mac_max);
	else if (!strcmp(what, "inc") )
		inet_mtoh64((struct ether_addr *)mac, &info->range.dst_mac_inc);
	else if (!strcmp(what, "start") ) {
		inet_mtoh64((struct ether_addr *)mac, &info->range.dst_mac);
		/* Changes add below to reflect MAC value in range */
		memcpy(&info->seq_pkt[RANGE_PKT].eth_dst_addr, mac->mac, 6);
	}
}

/**************************************************************************//**
 *
 * pktgen_set_src_mac - Set the source MAC address for the ports.
 *
 * DESCRIPTION
 * Set the source MAC address for the ports given in the list.
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

void
pktgen_set_src_mac(port_info_t *info, const char *what,
                   cmdline_etheraddr_t *mac)
{
	if (!strcmp(what, "min") )
		inet_mtoh64((struct ether_addr *)mac, &info->range.src_mac_min);
	else if (!strcmp(what, "max") )
		inet_mtoh64((struct ether_addr *)mac, &info->range.src_mac_max);
	else if (!strcmp(what, "inc") )
		inet_mtoh64((struct ether_addr *)mac, &info->range.src_mac_inc);
	else if (!strcmp(what, "start") ) {
		inet_mtoh64((struct ether_addr *)mac, &info->range.src_mac);
		/* Changes add below to reflect MAC value in range */
		memcpy(&info->seq_pkt[RANGE_PKT].eth_src_addr, mac->mac, 6);
	}
}

/**************************************************************************//**
 *
 * pktgen_set_src_ip - Set the source IP address value.
 *
 * DESCRIPTION
 * Set the source IP address for all of the ports listed.
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

void
pktgen_set_src_ip(port_info_t *info, char *what, cmdline_ipaddr_t *ip)
{
	if (!strcmp(what, "min") )
		info->range.src_ip_min = ntohl(ip->addr.ipv4.s_addr);
	else if (!strcmp(what, "max") )
		info->range.src_ip_max = ntohl(ip->addr.ipv4.s_addr);
	else if (!strcmp(what, "inc") )
		info->range.src_ip_inc = ntohl(ip->addr.ipv4.s_addr);
	else if (!strcmp(what, "start") )
		info->range.src_ip = ntohl(ip->addr.ipv4.s_addr);
}

/**************************************************************************//**
 *
 * pktgen_set_dst_ip - Set the destination IP address values
 *
 * DESCRIPTION
 * Set the destination IP address values.
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

void
pktgen_set_dst_ip(port_info_t *info, char *what, cmdline_ipaddr_t *ip)
{
	if (!strcmp(what, "min") )
		info->range.dst_ip_min = ntohl(ip->addr.ipv4.s_addr);
	else if (!strcmp(what, "max") )
		info->range.dst_ip_max = ntohl(ip->addr.ipv4.s_addr);
	else if (!strcmp(what, "inc") )
		info->range.dst_ip_inc = ntohl(ip->addr.ipv4.s_addr);
	else if (!strcmp(what, "start") )
		info->range.dst_ip = ntohl(ip->addr.ipv4.s_addr);
}

/**************************************************************************//**
 *
 * pktgen_set_src_port - Set the source IP port number for the ports
 *
 * DESCRIPTION
 * Set the source IP port number for the ports listed.
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

void
pktgen_set_src_port(port_info_t *info, char *what, uint16_t port)
{
	if (!strcmp(what, "inc") ) {
		if (port > 64)
			port = 64;
		info->range.src_port_inc = port;
	} else {
		if (!strcmp(what, "min") )
			info->range.src_port_min = port;
		else if (!strcmp(what, "max") )
			info->range.src_port_max = port;
		else if (!strcmp(what, "start") )
			info->range.src_port = port;
	}
}

/**************************************************************************//**
 *
 * pktgen_set_gtpu_teid - Set the TEID for GTPU header
 *
 * DESCRIPTION
 * Set the GTP-U TEID for the ports listed.
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

void
pktgen_set_gtpu_teid(port_info_t *info, char *what, uint32_t teid)
{
	if (!strcmp(what, "inc") ) {
		if (teid != 0)
			info->range.gtpu_teid_inc = teid;
	} else {
		if (!strcmp(what, "min") )
			info->range.gtpu_teid_min = teid;
		else if (!strcmp(what, "max") )
			info->range.gtpu_teid_max = teid;
		else if (!strcmp(what, "start") ) {
			info->range.gtpu_teid = teid;
			info->seq_pkt[RANGE_PKT].gtpu_teid = teid;
		}
	}
}

/**************************************************************************//**
 *
 * pktgen_set_dst_port - Set the destination port value
 *
 * DESCRIPTION
 * Set the destination port values.
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

void
pktgen_set_dst_port(port_info_t *info, char *what, uint16_t port)
{
	if (!strcmp(what, "inc") ) {
		if (port > 64)
			port = 64;
		info->range.dst_port_inc = port;
	} else {
		if (!strcmp(what, "min") )
			info->range.dst_port_min = port;
		else if (!strcmp(what, "max") )
			info->range.dst_port_max = port;
		else if (!strcmp(what, "start") )
			info->range.dst_port = port;
	}
}

/**************************************************************************//**
 *
 * pktgen_set_vlan_id - Set the VLAN id value
 *
 * DESCRIPTION
 * Set the VLAN id values.
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

void
pktgen_set_vlan_id(port_info_t *info, char *what, uint16_t id)
{
	if (!strcmp(what, "inc") ) {
		if (id > 64)
			id = 64;
		info->range.vlan_id_inc = id;
	} else {
		if ( (id < MIN_VLAN_ID) || (id > MAX_VLAN_ID) )
			id = MIN_VLAN_ID;

		if (!strcmp(what, "min") )
			info->range.vlan_id_min = id;
		else if (!strcmp(what, "max") )
			info->range.vlan_id_max = id;
		else if (!strcmp(what, "start") )
			info->range.vlan_id = id;
	}
}

/**************************************************************************//**
 *
 * pktgen_set_range_pkt_size - Set the Packet size value
 *
 * DESCRIPTION
 * Set the packet size values.
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

void
pktgen_set_range_pkt_size(port_info_t *info, char *what, uint16_t size)
{
	if (!strcmp(what, "inc") ) {
		if (size > ETHER_MIN_LEN)
			size = ETHER_MIN_LEN;

		info->range.pkt_size_inc = size;
	} else {
		if (size < ETHER_MIN_LEN)
			size = MIN_PKT_SIZE;
		else if (size > ETHER_MAX_LEN)
			size = MAX_PKT_SIZE;
		else
			size -= FCS_SIZE;

		if (!strcmp(what, "start") )
			info->range.pkt_size = size;
		else if (!strcmp(what, "min") )
			info->range.pkt_size_min = size;
		else if (!strcmp(what, "max") )
			info->range.pkt_size_max = size;
	}
}

/**************************************************************************//**
 *
 * pktgen_send_arp_requests - Send an ARP request for a given port.
 *
 * DESCRIPTION
 * Using the port list do an ARp send for all ports.
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

void
pktgen_send_arp_requests(port_info_t *info, uint32_t type)
{
	if (type == GRATUITOUS_ARP)
		pktgen_set_port_flags(info, SEND_GRATUITOUS_ARP);
	else
		pktgen_set_port_flags(info, SEND_ARP_REQUEST);
}

/**************************************************************************//**
 *
 * pktgen_set_page - Set the page type to display
 *
 * DESCRIPTION
 * Set the page type ot display
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

void
pktgen_set_page(char *str)
{
	uint16_t page;

	if (str == NULL)
		return;

	page = atoi(str);
	if (page > pktgen.nb_ports)
		return;

	/* Switch to the correct page */
	if (str[0] == 'n') {
		pcap_info_t *pcap = pktgen.info[pktgen.portNum].pcap;

		if (pcap) {
			if ( (pcap->pkt_idx + PCAP_PAGE_SIZE) < pcap->pkt_count)
				pcap->pkt_idx += PCAP_PAGE_SIZE;
			else
				pcap->pkt_idx = 0;
		}
		pktgen.flags |= PRINT_LABELS_FLAG;
	} else if ( (str[0] == 'c') && (str[1] == 'p') ) {
		pktgen.flags &= ~PAGE_MASK_BITS;
		pktgen.flags |= CPU_PAGE_FLAG;
	} else if (str[0] == 'p') {
		pktgen.flags &= ~PAGE_MASK_BITS;
		pktgen.flags |= PCAP_PAGE_FLAG;
		if (pktgen.info[pktgen.portNum].pcap)
			pktgen.info[pktgen.portNum].pcap->pkt_idx = 0;
	} else if ( ( str[0] == 'r' ) && (str[1] == 'a') ) {
		pktgen.flags &= ~PAGE_MASK_BITS;
		pktgen.flags |= RANGE_PAGE_FLAG;
	} else if (str[0] == 'c') {
		pktgen.flags &= ~PAGE_MASK_BITS;
		pktgen.flags |= CONFIG_PAGE_FLAG;
	} else if (str[0] == 's') {
		pktgen.flags &= ~PAGE_MASK_BITS;
		pktgen.flags |= SEQUENCE_PAGE_FLAG;
	} else if (str[0] == 'r') {
		pktgen.flags &= ~PAGE_MASK_BITS;
		pktgen.flags |= RND_BITFIELD_PAGE_FLAG;
	} else if (str[0] == 'l') {
		pktgen.flags &= ~PAGE_MASK_BITS;
		pktgen.flags |= LOG_PAGE_FLAG;
	} else {
		uint16_t start_port;
		if (str[0] == 'm')
			page = 0;
		start_port = (page * pktgen.nb_ports_per_page);
		if ( (pktgen.starting_port != start_port) &&
		     (start_port < pktgen.nb_ports) ) {
			pktgen.starting_port    = start_port;
			pktgen.ending_port      = start_port +
			        pktgen.nb_ports_per_page;
			if (pktgen.ending_port >
			    (pktgen.starting_port + pktgen.nb_ports) )
				pktgen.ending_port =
				        (pktgen.starting_port +
				         pktgen.nb_ports);
		}
		if (pktgen.flags & PAGE_MASK_BITS) {
			pktgen.flags &= ~PAGE_MASK_BITS;
			pktgen.flags |= PRINT_LABELS_FLAG;
		}
	}
	pktgen_redisplay(1);
}

/**************************************************************************//**
 *
 * pktgen_set_seq - Set a sequence packet for given port
 *
 * DESCRIPTION
 * Set the sequence packet information for all ports listed.
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

void
pktgen_set_seq(port_info_t *info, uint32_t seqnum,
               cmdline_etheraddr_t *daddr, cmdline_etheraddr_t *saddr,
               cmdline_ipaddr_t *ip_daddr, cmdline_ipaddr_t *ip_saddr,
               uint32_t sport, uint32_t dport, char type, char proto,
               uint16_t vlanid, uint32_t pktsize, uint32_t gtpu_teid)
{
	pkt_seq_t     *pkt;

	pkt = &info->seq_pkt[seqnum];
	memcpy(&pkt->eth_dst_addr, daddr->mac, 6);
	memcpy(&pkt->eth_src_addr, saddr->mac, 6);
	pkt->ip_mask = size_to_mask(ip_saddr->prefixlen);
	if (type == '4') {
		pkt->ip_src_addr.addr.ipv4.s_addr = htonl(ip_saddr->addr.ipv4.s_addr);
		pkt->ip_dst_addr.addr.ipv4.s_addr = htonl(ip_daddr->addr.ipv4.s_addr);
	} else {
		memcpy(&pkt->ip_src_addr.addr.ipv6.__in6_u.__u6_addr8,
			ip_saddr->addr.ipv6.__in6_u.__u6_addr8, sizeof(struct in6_addr));
		memcpy(&pkt->ip_dst_addr.addr.ipv6.__in6_u.__u6_addr8,
			ip_daddr->addr.ipv6.__in6_u.__u6_addr8, sizeof(struct in6_addr));
	}
	pkt->dport          = dport;
	pkt->sport          = sport;
	pkt->pktSize        = pktsize - FCS_SIZE;
	pkt->ipProto        = (proto == 'u') ? PG_IPPROTO_UDP :
	        (proto == 'i') ? PG_IPPROTO_ICMP : PG_IPPROTO_TCP;
	/* Force the IP protocol to IPv4 if this is a ICMP packet. */
	if (proto == 'i')
		type = '4';
	pkt->ethType        = (type == '6') ? ETHER_TYPE_IPv6 : ETHER_TYPE_IPv4;
	pkt->vlanid         = vlanid;
	pkt->gtpu_teid      = gtpu_teid;
	pktgen_packet_ctor(info, seqnum, -1);
}

/**************************************************************************//**
 *
 * pktgen_compile_pkt - Compile a packet for a given port.
 *
 * DESCRIPTION
 * Compile a packet for a given port.
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

void
pktgen_compile_pkt(port_info_t *info, uint32_t seqnum,
                   cmdline_etheraddr_t *daddr, cmdline_etheraddr_t *saddr,
                   cmdline_ipaddr_t *ip_daddr, cmdline_ipaddr_t *ip_saddr,
                   uint32_t sport, uint32_t dport, char type, char proto,
                   uint16_t vlanid, uint32_t pktsize, uint32_t gtpu_teid)
{
	pkt_seq_t     *pkt;

	if (seqnum >= NUM_EXTRA_TX_PKTS)
		return;

	pkt = &info->seq_pkt[seqnum + EXTRA_TX_PKT];

	memcpy(&pkt->eth_dst_addr, daddr->mac, 6);
	memcpy(&pkt->eth_src_addr, saddr->mac, 6);
	pkt->ip_mask        = size_to_mask(ip_saddr->prefixlen);
	pkt->ip_src_addr.addr.ipv4.s_addr    = htonl(ip_saddr->addr.ipv4.s_addr);
	pkt->ip_dst_addr.addr.ipv4.s_addr    = htonl(ip_daddr->addr.ipv4.s_addr);
	pkt->dport          = dport;
	pkt->sport          = sport;
	pkt->pktSize        = pktsize - FCS_SIZE;
	pkt->ipProto        = (proto == 'u') ? PG_IPPROTO_UDP :
	        (proto == 'i') ? PG_IPPROTO_ICMP : PG_IPPROTO_TCP;
	/* Force the IP protocol to IPv4 if this is a ICMP packet. */
	if (proto == 'i')
		type = '4';
	pkt->ethType        = (type == '4') ? ETHER_TYPE_IPv4 :
	        (type == '6') ? ETHER_TYPE_IPv6 :
	        (type == 'n') ? ETHER_TYPE_VLAN : ETHER_TYPE_IPv4;
	pkt->vlanid         = vlanid;
	pkt->gtpu_teid          = gtpu_teid;
	pktgen_packet_ctor(info, seqnum, -1);
}

/**************************************************************************//**
 *
 * pktgen_send_pkt - Send a packet from the sequence array.
 *
 * DESCRIPTION
 * Send a packet from the special pkt_seq_t structures. Seqnum is the 0-N
 * index value into the info.seq_pkt[] array for EXTRA_TX_PKTS.
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

void
pktgen_send_pkt(port_info_t *info, uint32_t seqnum)
{
	pktgen_send_seq_pkt(info, seqnum + EXTRA_TX_PKT);
}

/**************************************************************************//**
 *
 * pktgen_recv_pkt - Receive a packet from the sequence array.
 *
 * DESCRIPTION
 * Receive a packet from the special pkt_seq_t structures.
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

void
pktgen_recv_pkt(port_info_t *info __rte_unused)
{
	pktgen_log_warning("Not working yet!");
}

/**************************************************************************//**
 *
 * pktgen_quit - Exit pktgen.
 *
 * DESCRIPTION
 * Close and exit Pktgen.
 *
 * RETURNS: N/A
 *
 * SEE ALSO:
 */

void
pktgen_quit(void)
{
	cmdline_quit(pktgen.cl);
}