forked from sckevmit/vrouter-pktgen-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.lua
33 lines (27 loc) · 1.37 KB
/
functions.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
--
-- Pktgen-DPDK Contrail-vRouter test script
-- File with helper functions.
--
-- Copyright (c) 2015 Semihalf. All rights reserved.
--
function write_stats_to_file(log_file, sendport, rcvport, time)
local file = io.open(log_file, "w");
local stats = pktgen.portStats(sendport..","..rcvport, "port");
local sentpkts = stats[tonumber(sendport)].opackets;
local rcvdpkts = stats[tonumber(rcvport)].ipackets;
file:write(string.format("\n*** RESULT:\tFinished in\t\t%d seconds\n", time));
file:write(string.format("\t\tsent %d pkts\t%.4f Mpkts/sec\n", sentpkts, (sentpkts/1000000)/time));
file:write(string.format("\t\trcvd %d pkts\t%.4f Mpkts/sec\n", rcvdpkts, (rcvdpkts/1000000)/time));
file:write(string.format("\t\tdeltapkts(TX - RX):\t%d pkts\n***\n", sentpkts-rcvdpkts));
file:write(string.format("Pktgen-DPDK port %d dump:", sendport), "\n\n");
-- file:write(serialize("linkState", pktgen.linkState(sendport)));
-- file:write(serialize("isSending", pktgen.isSending(sendport)));
file:write(serialize("portSizes", pktgen.portSizes(sendport)));
file:write(serialize("pktStats", pktgen.pktStats(sendport)));
file:write(serialize("portRates", pktgen.portStats(sendport, "rate")));
file:write(serialize("portStats", pktgen.portStats(sendport, "port")));
file:close();
end
function os_sleep(n)
os.execute("sleep " .. tonumber(n))
end