hmbdc
simplify-high-performance-messaging-programming
ping-pong-tcpcast.cpp
#define HMBDC_LOG_CONTEXT hmbdc::app::Context<24>
#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) {
SingletonGuardian<HMBDC_LOGGER> logGuard(std::cout);
using namespace std;
string type;
string role;
string ifaceAddr;
uint16_t startCore;
size_t skipFirst;
uint16_t msgSize;
uint16_t msgPerSec;
uint32_t runTime;
auto CONFIG = R"|(
{
"outBufferSizePower2" : 5,
"nagling" : false,
"ping" : {
"topicRegex" : "ping"
},
"pong" : {
"topicRegex" : "pong"
}
}
)|";
namespace po = boost::program_options;
po::options_description desc("Allowed options");
auto helpStr =
"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-1024")
("msgPerSec", po::value<uint16_t>(&msgPerSec)->default_value(1), "msg per second up to 1000")
("ifaceAddr,I", po::value<string>(&ifaceAddr), "interface to use, for example: 192.168.0.101 or 192.168.1.0/24.")
("startCore,C", po::value<uint16_t>(&startCore)->default_value(0u), "specify starting core number")
("skipFirst", po::value<size_t>(&skipFirst)->default_value(1u), "skipp the first N results (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 config(CONFIG);
config.put("ifaceAddr", ifaceAddr);
config.put("startCore", startCore);
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);
} else if (role == "pong") {
config.put("ping", false);
return pingpong<NetContext>(config);
} else {
cout << desc << "\n";
return -1;
}
}