33 #define CREATE_CHUNK_SIZE 2048
50 double wait=(timeout*1000);
60 }
catch (
const std::string &errmsg) {
61 std::cerr << errmsg << std::endl;
68 void echo(
EID destination,
int size,
int lifetime,
bool encryption =
false,
bool sign =
false)
99 (*stream).write((
char*)&seq, 4);
107 for (
size_t i = 0; i <
sizeof(pattern); ++i)
109 pattern[i] =
static_cast<char>(
static_cast<int>(
'0') + (i % 10));
117 (*stream).write(pattern, size);
130 size_t reply_seq = 0;
132 blob.
iostream()->read((
char *)(&reply_seq),4 );
134 if (reply_seq != seq) {
135 std::stringstream ss;
136 ss <<
"sequence number mismatch, awaited " << seq <<
", got " << reply_seq;
140 throw std::string(
"ignoring bundle from source " + bundle.
source.
getString() +
" awaited " + lastdestination);
147 string lastdestination;
154 cout <<
"-- dtnping (IBR-DTN) --" << endl;
155 cout <<
"Syntax: dtnping [options] <dst>" << endl;
156 cout <<
" <dst> Set the destination eid (e.g. dtn://node/echo)" << endl << endl;
157 cout <<
"* optional parameters *" << endl;
158 cout <<
" -h|--help Display this text" << endl;
159 cout <<
" --src <name> Set the source application name (e.g. echo-client)" << endl;
160 cout <<
" --nowait Do not wait for a reply" << endl;
161 cout <<
" --abortfail Abort after first packetloss" << endl;
162 cout <<
" --size The size of the payload" << endl;
163 cout <<
" --count <n> Send X echo in a row" << endl;
164 cout <<
" --delay <seconds>" << endl;
165 cout <<
" Delay between a received response and the next request" << endl;
166 cout <<
" --lifetime <seconds>" << endl;
167 cout <<
" Set the lifetime of outgoing bundles; default: 30" << endl;
168 cout <<
" --encrypt Request encryption on the bundle layer" << endl;
169 cout <<
" --sign Request signature on the bundle layer" << endl;
170 cout <<
" -U <socket> Connect to UNIX domain socket API" << endl;
189 double avg_value = 0;
192 std::cout << std::endl <<
"--- " << _addr.
getString() <<
" echo statistics --- " << std::endl;
193 std::cout <<
_transmitted <<
" bundles transmitted, " <<
_received <<
" received, " << loss <<
"% bundle loss, time " << _runtime << std::endl;
194 std::cout <<
"rtt min/avg/max = ";
207 if (__client != NULL) __client->
abort();
214 int main(
int argc,
char *argv[])
218 sighandler.
handle(SIGINT);
219 sighandler.
handle(SIGTERM);
222 string ping_destination =
"dtn://local/echo";
223 string ping_source =
"";
225 unsigned int lifetime = 30;
226 bool wait_for_reply =
true;
227 bool stop_after_first_fail =
false;
229 size_t interval_pause = 1;
233 bool bundle_encryption =
false;
234 bool bundle_signed =
false;
242 for (
int i = 1; i < argc; ++i)
244 string arg = argv[i];
247 if ((arg ==
"-h") || (arg ==
"--help"))
253 else if (arg ==
"--encrypt")
255 bundle_encryption =
true;
258 else if (arg ==
"--sign")
260 bundle_signed =
true;
263 else if (arg ==
"--nowait")
266 wait_for_reply =
false;
269 else if ( arg ==
"--abortfail") {
270 stop_after_first_fail=
true;
273 else if (arg ==
"--src" && argc > i)
275 ping_source = argv[i + 1];
279 else if (arg ==
"--size" && argc > i)
281 stringstream str_size;
282 str_size.str( argv[i + 1] );
283 str_size >> ping_size;
287 else if (arg ==
"--count" && argc > i)
289 stringstream str_count;
290 str_count.str( argv[i + 1] );
296 else if (arg ==
"--delay" && argc > i)
298 stringstream str_delay;
299 str_delay.str( argv[i + 1] );
300 str_delay >> interval_pause;
304 else if (arg ==
"--lifetime" && argc > i)
306 stringstream data; data << argv[i + 1];
310 else if (arg ==
"-U" && argc > i)
314 std::cout <<
"argument missing!" << std::endl;
323 ping_destination = argv[argc - 1];
326 _addr =
EID(ping_destination);
351 EchoClient client(mode, ping_source, conn);
363 std::cout <<
"ECHO " << _addr.
getString() <<
" " << ping_size <<
" bytes of data." << std::endl;
369 for (
unsigned int i = 0; (i < count) || nonstop; ++i)
375 client.echo( _addr, ping_size, lifetime, bundle_encryption, bundle_signed );
387 size_t reply_seq = 0;
388 size_t payload_size = 0;
397 blob.
iostream()->read((
char *)(&reply_seq),4 );
398 payload_size = blob.
size();
401 std::cout << payload_size <<
" bytes from " << response.
source.
getString() <<
": seq=" << reply_seq <<
" ttl=" << response.
lifetime.
toString() <<
" time=" << tm << std::endl;
404 if (stop_after_first_fail)
407 std::cout <<
"Timeout." << std::endl;
410 if (interval_pause > 0)
413 __pause.
wait(interval_pause * 1000);
426 if (stop_after_first_fail)
428 std::cout <<
"No response, aborting." << std::endl;
435 std::cerr <<
"Disconnected." << std::endl;
437 std::cerr <<
"Error while receiving a bundle." << std::endl;
444 std::cerr <<
"Can not connect to the daemon. Does it run?" << std::endl;
446 }
catch (
const std::exception&) {
447 std::cerr <<
"unknown error" << std::endl;