#include "hmbdc/app/utils/Pingpong.hpp"
#include "hmbdc/app/mcast/NetContext.hpp"
#include <boost/program_options.hpp>
int
main(int argc, char** argv) {
string type;
string role;
string ifaceAddr;
vector<uint16_t> cpus;
size_t skipFirst;
uint16_t msgSize;
uint16_t msgPerSec;
uint32_t runTime;
auto CONFIG = R"|(
{
"ping" : {
"topicRegex" : "ping"
},
"pong" : {
"topicRegex" : "pong"
}
}
)|";
namespace po = boost::program_options;
po::options_description desc("Allowed options");
auto helpStr =
"Warning: hmbdc mcast messaging uses multicast functions and it is imperative that multicast is enabled (stop the firewall?) on your network for this to work."
"This program can be used to test round trip hmbdc mcast message latency among a group of hosts."
"The source code is in example dir: ping-pong-mcast.cpp"
"\nUsage example: \nponger$ sudo ./ping-pong-mcast -I 192.168.2.101"
"\npinger$ sudo ./ping-pong-mcast -r ping -I 192.168.2.100"
"\nwould start the test using two host ponger and pinger with default settings."
;
desc.add_options()
("help", helpStr)
("role,r", po::value<string>(&role)->default_value("pong"), "ping or pong")
("msgSize", po::value<uint16_t>(&msgSize)->default_value(16), "msg size: 16-1000")
("msgPerSec", po::value<uint16_t>(&msgPerSec)->default_value(1), "msg per second up to 65535")
("ifaceAddr,I", po::value<string>(&ifaceAddr), "interface to use, for example: 192.168.0.101 or 192.168.1.0/24.")
("cpus", po::value(&cpus)->multitoken()->default_value({0, 1, 2}, "0 1 2"), "specify the 3 cpu index numbers used in the test (recv, send engines, and 1 for msg client)")
("skipFirst", po::value<size_t>(&skipFirst)->default_value(1u), "skipp the first N results (buffering & warming up stage) when collecting latency stats")
("runTime", po::value<uint32_t>(&runTime)->default_value(0), "how many seconds does the test last before exit. By default it runs forever")
;
po::positional_options_description p;
po::variables_map vm;
po::store(po::command_line_parser(argc, argv).
options(desc).positional(p).run(), vm);
po::notify(vm);
if (vm.count("help")) {
cout << desc << "\n";
return 0;
}
config.put("ifaceAddr", ifaceAddr);
config.put("skipFirst", skipFirst);
config.put("msgSize", msgSize);
config.put("msgPerSec", msgPerSec);
config.put("runTime", runTime);
if (role == "ping" ) {
config.put("ping", true);
return pingpong<NetContext>(config, cpus);
} else if (role == "pong") {
config.put("ping", false);
return pingpong<NetContext>(config, cpus);
} else {
cout << desc << "\n";
return -1;
}
}