Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Pktgen-DPDK Lua Scripts
--
-- L2fwd, L3fwd-LPM test script
-- Send packets for x seconds; return how many packets has been sent.
--
-- Copyright (c) 2020 mishal23. All rights reserved.
--
package.path = package.path ..";?.lua;test/?.lua;app/?.lua;"
require "Pktgen";
local sendport = "0";
local rcvport = "1";
local port2 = "2";
local port3 = "3";
local srcip = "198.18.0.1";
local dstip = "198.18.1.1";
local port2ip = "198.18.2.1";
local port3ip = "198.18.3.1";
local src_mac = "3C:FD:FE:7C:BC:E0";
local dst_mac = "3C:FD:FE:7C:BC:E1";
local mac2 = "3C:FD:FE:7C:BC:E2";
local mac3 = "3C:FD:FE:7C:BC:E3";
-- local rate = 100;
local send_for_secs = 30; --2mins
-- set ip
pktgen.set_ipaddr(sendport, "dst", dstip);
pktgen.set_ipaddr(sendport, "src", srcip);
pktgen.set_ipaddr(rcvport, "dst", srcip);
pktgen.set_ipaddr(rcvport, "src", dstip);
pktgen.set_ipaddr(port2, "dst", port3ip);
pktgen.set_ipaddr(port2, "src", port2ip);
pktgen.set_ipaddr(port3, "dst", port2ip);
pktgen.set_ipaddr(port3, "src", port3ip);
-- set mac
pktgen.set_mac(sendport, "dst", src_mac);
pktgen.set_mac(rcvport, "dst", dst_mac);
pktgen.set_mac(port2, "dst", mac2);
pktgen.set_mac(port3, "dst", mac3);
local pktSize = tonumber(pktgen.input("Size of packets to send (64-1518B): "));
if pktSize == nil then
pktSize = 64;
end
local rate = tonumber(pktgen.input("Enter the sending rate (0-100%): "));
if rate == nil then
rate = 100;
end
-- set packet size
pktgen.set(sendport, "size", pktSize);
pktgen.set(rcvport, "size", pktSize);
pktgen.set(port2, "size", pktSize);
pktgen.set(port3, "size", pktSize);
-- set rate
pktgen.set(sendport, "rate", rate);
pktgen.set(rcvport, "rate", rate);
pktgen.set(port2, "rate", rate);
pktgen.set(port3, "rate", rate);
pktgen.set_proto("all", "udp");
printf("\n*** Sending %dB packets for %d seconds at rate %d ***\n", pktSize, send_for_secs, rate);
pktgen.start(sendport);
pktgen.start(port2);
local start_time = os.time();
while os.difftime(os.time(), start_time) < send_for_secs do
sleep(1);
end
pktgen.stop(sendport);
pktgen.stop(port2);
sleep(5);
local stats = pktgen.portStats(sendport..","..rcvport, "port");
local sentpkts = stats[tonumber(sendport)].opackets;
local rcvdpkts = stats[tonumber(rcvport)].ipackets;
local stats1 = pktgen.portStats(port2..","..port3, "port");
local sentpkts1 = stats1[tonumber(port2)].opackets;
local rcvdpkts1 = stats1[tonumber(port3)].ipackets;
printf("\nFinished in %d seconds", send_for_secs);
printf("\nsent port0 %d pkts, %.4f Mpkts/sec\n", sentpkts, (sentpkts/1000000)/send_for_secs);
printf("\nreceived port1 %d pkts, %.4f Mpkts/sec\n", rcvdpkts, (rcvdpkts/1000000)/send_for_secs);
printf("\nsent port2 %d pkts, %.4f Mpkts/sec\n", sentpkts1, (sentpkts1/1000000)/send_for_secs);
printf("\nreceived port3 %d pkts, %.4f Mpkts/sec\n", rcvdpkts1, (rcvdpkts1/1000000)/send_for_secs);
--
-- l3fwd-em script
-- Send packets for x seconds; return how many packets has been sent.
--
-- Copyright (c) 2020 mishal23. All rights reserved.
--
package.path = package.path ..";?.lua;test/?.lua;app/?.lua;"
require "Pktgen";
local sendport = "0";
local rcvport = "1";
local port2 = "2";
local port3 = "3";
local srcip = "198.18.0.1";
local dstip = "198.18.1.1";
local port2ip = "198.18.2.1";
local port3ip = "198.18.3.1";
local src_mac = "3C:FD:FE:7C:BC:E0";
local dst_mac = "3C:FD:FE:7C:BC:E1";
local mac2 = "3C:FD:FE:7C:BC:E2";
local mac3 = "3C:FD:FE:7C:BC:E3";
-- local rate = 100;
local send_for_secs = 120; --2mins
-- set ip
-- pktgen.set_ipaddr(sendport, "dst", "201.0.0.1");
-- pktgen.set_ipaddr(sendport, "src", "200.20.0.1");
-- pktgen.set_ipaddr(rcvport, "dst", "101.0.0.1");
-- pktgen.set_ipaddr(rcvport, "src", "100.10.0.1");
pktgen.set_ipaddr(sendport, "dst", "201.0.0.0");
pktgen.set_ipaddr(sendport, "src", "200.20.0.1");
pktgen.set_ipaddr(rcvport, "dst", "101.0.0.0");
pktgen.set_ipaddr(rcvport, "src", "100.10.0.1");
pktgen.set_ipaddr(port2, "dst", "211.0.0.0");
pktgen.set_ipaddr(port2, "src", "200.40.0.1");
pktgen.set_ipaddr(port3, "dst", "111.0.0.0");
pktgen.set_ipaddr(port3, "src", "100.30.0.1");
-- set mac
pktgen.set_mac(sendport, "dst", src_mac);
pktgen.set_mac(rcvport, "dst", dst_mac);
pktgen.set_mac(port2, "dst", mac2);
pktgen.set_mac(port3, "dst", mac3);
pktgen.set("0", "sport", 12);
pktgen.set("0", "dport", 102);
pktgen.set("1", "sport", 11);
pktgen.set("1", "dport", 101);
pktgen.set("2", "sport", 12);
pktgen.set("2", "dport", 102);
pktgen.set("3", "sport", 11);
pktgen.set("3", "dport", 101);
local pktSize = tonumber(pktgen.input("Size of packets to send (64-1518B): "));
-- local pktSize = 64
if pktSize == nil then
pktSize = 64;
end
local rate = tonumber(pktgen.input("Enter the sending rate (0-100%): "));
if rate == nil then
rate = 100;
end
-- set packet size
pktgen.set(sendport, "size", pktSize);
pktgen.set(rcvport, "size", pktSize);
pktgen.set(port2, "size", pktSize);
pktgen.set(port3, "size", pktSize);
-- set rate
pktgen.set(sendport, "rate", rate);
pktgen.set(rcvport, "rate", rate);
pktgen.set(port2, "rate", rate);
pktgen.set(port3, "rate", rate);
pktgen.set_proto("all", "tcp");
printf("\n*** Sending %dB packets for %d seconds at rate %d ***\n", pktSize, send_for_secs, rate);
pktgen.start(sendport);
-- pktgen.start(rcvport);
pktgen.start(port2);
-- pktgen.start(port3);
local start_time = os.time();
while os.difftime(os.time(), start_time) < send_for_secs do
sleep(1);
end
pktgen.stop(sendport);
-- pktgen.stop(rcvport);
pktgen.stop(port2);
-- pktgen.stop(port3);
sleep(5);
local stats = pktgen.portStats(sendport..","..rcvport, "port");
local sentpkts = stats[tonumber(sendport)].opackets;
local rcvdpkts = stats[tonumber(rcvport)].ipackets;
local stats1 = pktgen.portStats(port2..","..port3, "port");
local sentpkts1 = stats1[tonumber(port2)].opackets;
local rcvdpkts1 = stats1[tonumber(port3)].ipackets;
printf("\nFinished in %d seconds", send_for_secs);
printf("\nsent port0 %d pkts, %.4f Mpkts/sec\n", sentpkts, (sentpkts/1000000)/send_for_secs);
printf("\nreceived port1 %d pkts, %.4f Mpkts/sec\n", rcvdpkts, (rcvdpkts/1000000)/send_for_secs);
printf("\nsent port2 %d pkts, %.4f Mpkts/sec\n", sentpkts1, (sentpkts1/1000000)/send_for_secs);
printf("\nreceived port3 %d pkts, %.4f Mpkts/sec\n", rcvdpkts1, (rcvdpkts1/1000000)/send_for_secs);
--
-- l3fwd-power script
-- Send packets for x seconds; return how many packets has been sent.
--
-- Copyright (c) 2020 mishal23. All rights reserved.
--
package.path = package.path ..";?.lua;test/?.lua;app/?.lua;"
require "Pktgen";
local sendport = "0";
local rcvport = "1";
local port2 = "2";
local port3 = "3";
local srcip = "1.1.1.1";
local dstip = "2.1.1.1";
local port2ip = "3.1.1.1";
local port3ip = "4.1.1.1";
local src_mac = "3C:FD:FE:7C:BC:E0";
local dst_mac = "3C:FD:FE:7C:BC:E1";
local mac2 = "3C:FD:FE:7C:BC:E2";
local mac3 = "3C:FD:FE:7C:BC:E3";
-- local rate = 100;
local send_for_secs = 130; --2mins
-- set ip
pktgen.set_ipaddr(sendport, "dst", dstip);
pktgen.set_ipaddr(sendport, "src", srcip);
pktgen.set_ipaddr(rcvport, "dst", srcip);
pktgen.set_ipaddr(rcvport, "src", dstip);
pktgen.set_ipaddr(port2, "dst", port3ip);
pktgen.set_ipaddr(port2, "src", port2ip);
pktgen.set_ipaddr(port3, "dst", port2ip);
pktgen.set_ipaddr(port3, "src", port3ip);
-- set mac
pktgen.set_mac(sendport, "dst", src_mac);
pktgen.set_mac(rcvport, "dst", dst_mac);
pktgen.set_mac(port2, "dst", mac2);
pktgen.set_mac(port3, "dst", mac3);
local pktSize = tonumber(pktgen.input("Size of packets to send (64-1518B): "));
-- local pktSize = 64
if pktSize == nil then
pktSize = 64;
end
local rate = tonumber(pktgen.input("Enter the sending rate (0-100%): "));
if rate == nil then
rate = 100;
end
-- set packet size
pktgen.set(sendport, "size", pktSize);
pktgen.set(rcvport, "size", pktSize);
pktgen.set(port2, "size", pktSize);
pktgen.set(port3, "size", pktSize);
-- set rate
pktgen.set(sendport, "rate", rate);
pktgen.set(rcvport, "rate", rate);
pktgen.set(port2, "rate", rate);
pktgen.set(port3, "rate", rate);
pktgen.set_proto("all", "udp");
printf("\n*** Sending %dB packets for %d seconds at rate %d ***\n", pktSize, send_for_secs, rate);
pktgen.start(sendport);
-- pktgen.start(rcvport);
pktgen.start(port2);
-- pktgen.start(port3);
local start_time = os.time();
while os.difftime(os.time(), start_time) < send_for_secs do
sleep(1);
end
pktgen.stop(sendport);
-- pktgen.stop(rcvport);
pktgen.stop(port2);
-- pktgen.stop(port3);
sleep(5);
local stats = pktgen.portStats(sendport..","..rcvport, "port");
local sentpkts = stats[tonumber(sendport)].opackets;
local rcvdpkts = stats[tonumber(rcvport)].ipackets;
local stats1 = pktgen.portStats(port2..","..port3, "port");
local sentpkts1 = stats1[tonumber(port2)].opackets;
local rcvdpkts1 = stats1[tonumber(port3)].ipackets;
printf("\nFinished in %d seconds", send_for_secs);
printf("\nsent port0 %d pkts, %.4f Mpkts/sec\n", sentpkts, (sentpkts/1000000)/send_for_secs);
printf("\nreceived port1 %d pkts, %.4f Mpkts/sec\n", rcvdpkts, (rcvdpkts/1000000)/send_for_secs);
printf("\nsent port2 %d pkts, %.4f Mpkts/sec\n", sentpkts1, (sentpkts1/1000000)/send_for_secs);
printf("\nreceived port3 %d pkts, %.4f Mpkts/sec\n", rcvdpkts1, (rcvdpkts1/1000000)/send_for_secs);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment