Add Constant traffic generation LUA script for DPDK and PCAP files
[yardstick.git] / yardstick / vTC / apexlake / experimental_framework / packet_generators / dpdk_pktgen / constant_traffic.lua
1 -----------------------------------------------------------------------------
2 -- Copyright (c) 2015 Intel Research and Development Ireland Ltd.
3 --
4 -- Licensed under the Apache License, Version 2.0 (the "License");
5 -- you may not use this file except in compliance with the License.
6 -- You may obtain a copy of the License at
7 --
8 --      http://www.apache.org/licenses/LICENSE-2.0
9 --
10 -- Unless required by applicable law or agreed to in writing, software
11 -- distributed under the License is distributed on an "AS IS" BASIS,
12 -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 -- See the License for the specific language governing permissions and
14 -- limitations under the License.
15 -----------------------------------------------------------------------------
16
17 -----------------------------------
18 ----- Constant traffic sender -----
19 -----------------------------------
20
21 package.path = package.path ..";?.lua;test/?.lua;app/?.lua;../?.lua"
22 require "Pktgen";
23
24 ----- Packet Gen Configuration
25 local sendport = "0";
26 pktgen.vlan(sendport, "on");
27 pktgen.ping4("all");
28 pktgen.icmp_echo("all", "on");
29 pktgen.process("all", "on");
30
31
32 ----- Script Configuration
33 local traffic_delay = 0;
34 local traffic_rate = 0;
35 local out_file = "";
36
37
38 function start_traffic(rate)
39     local endStats, diff, prev, iteration, flag, found;
40     flag = false;
41     found = false;
42
43     -- Send traffic at the specified rate
44     print("Start Generation");
45     pktgen.set(sendport, "rate", rate);
46     sleep(1);
47     pktgen.start(sendport);
48     sleep(traffic_delay);
49     pktgen.stop(sendport);
50     print("Stop Generation");
51
52     -- Collect statistics about the experiment
53     endStats = pktgen.portStats("all", "port");
54     sent_packets = endStats[0].opackets
55     return sent_packets;
56 end
57
58
59 pktgen.clr();
60 print("INSTANTIATION VALIDATION TEST")
61
62 -- Write output on log file
63 file = io.open(out_file, "w");
64
65 -- Start experiment
66 packets = start_traffic(traffic_rate);
67 print("SENT PACKETS: " .. packets);
68 file:write(packets);
69
70 -- Close the log file
71 file:close();
72
73 -- Quit the environment
74 os.exit(1);