#include "hmbdc/app/utils/Pingpong.hpp"
#include "hmbdc/app/tcpcast/NetContext.hpp"
#include <boost/program_options.hpp>
using namespace hmbdc::app;
using namespace hmbdc::app::tcpcast;
using namespace hmbdc::app::utils;
int
main(int argc, char** argv) {
using namespace std;
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"|(
{
"nagling" : false,
"ping" : {
"topicRegex" : "ping"
},
"pong" : {
"topicRegex" : "pong"
}
}
)|";
namespace po = boost::program_options;
po::options_description desc("Allowed options");
auto helpStr =
"Warning: hmbdc tcpcast network messaging by default uses multicast functions and it is imperative that multicast is enabled (stop the firewall?) on your network for this test to work."
"for the usage of hmbdc-tcpcast WITHOUT multicast, see tryTopicSource method in RecvTransportEngine.hpp and mcastEmu* config param\n"
"This program can be used to test round trip hmbdc tcpcast message latency among a group of hosts."
"The source code is in example dir: ping-pong-tcpcast.cpp"
"\nUsage example: \nponger$ sudo ./ping-pong-tcpcast -I 192.168.2.101"
"\npinger$ sudo ./ping-pong-tcpcast -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;
}
}