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;
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 X send X echo in a row" << endl;
164 cout <<
" --delay X delay (seconds) after a successful response" << endl;
165 cout <<
" --lifetime <seconds> set the lifetime of outgoing bundles; default: 30" << endl;
166 cout <<
" --encrypt request encryption on the bundle layer" << endl;
167 cout <<
" --sign request signature on the bundle layer" << endl;
168 cout <<
" -U <socket> use UNIX domain sockets" << endl;
187 double avg_value = 0;
190 std::cout << std::endl <<
"--- " << _addr.
getString() <<
" echo statistics --- " << std::endl;
191 std::cout <<
_transmitted <<
" bundles transmitted, " <<
_received <<
" received, " << loss <<
"% bundle loss, time " << _runtime << std::endl;
192 std::cout <<
"rtt min/avg/max = ";
205 if (__client != NULL) __client->
abort();
212 int main(
int argc,
char *argv[])
215 signal(SIGINT,
term);
216 signal(SIGTERM,
term);
218 string ping_destination =
"dtn://local/echo";
219 string ping_source =
"";
221 unsigned int lifetime = 30;
222 bool wait_for_reply =
true;
223 bool stop_after_first_fail =
false;
225 size_t interval_pause = 1;
229 bool bundle_encryption =
false;
230 bool bundle_signed =
false;
238 for (
int i = 1; i < argc; ++i)
240 string arg = argv[i];
243 if ((arg ==
"-h") || (arg ==
"--help"))
249 else if (arg ==
"--encrypt")
251 bundle_encryption =
true;
254 else if (arg ==
"--sign")
256 bundle_signed =
true;
259 else if (arg ==
"--nowait")
262 wait_for_reply =
false;
265 else if ( arg ==
"--abortfail") {
266 stop_after_first_fail=
true;
269 else if (arg ==
"--src" && argc > i)
271 ping_source = argv[i + 1];
275 else if (arg ==
"--size" && argc > i)
277 stringstream str_size;
278 str_size.str( argv[i + 1] );
279 str_size >> ping_size;
283 else if (arg ==
"--count" && argc > i)
285 stringstream str_count;
286 str_count.str( argv[i + 1] );
292 else if (arg ==
"--delay" && argc > i)
294 stringstream str_delay;
295 str_delay.str( argv[i + 1] );
296 str_delay >> interval_pause;
300 else if (arg ==
"--lifetime" && argc > i)
302 stringstream data; data << argv[i + 1];
306 else if (arg ==
"-U" && argc > i)
310 std::cout <<
"argument missing!" << std::endl;
319 ping_destination = argv[argc - 1];
322 _addr =
EID(ping_destination);
347 EchoClient client(mode, ping_source, conn);
359 std::cout <<
"ECHO " << _addr.
getString() <<
" " << ping_size <<
" bytes of data." << std::endl;
365 for (
unsigned int i = 0; (i < count) || nonstop; ++i)
371 client.echo( _addr, ping_size, lifetime, bundle_encryption, bundle_signed );
383 size_t reply_seq = 0;
384 size_t payload_size = 0;
393 blob.
iostream()->read((
char *)(&reply_seq),4 );
397 std::cout << payload_size <<
" bytes from " << response.
source.
getString() <<
": seq=" << reply_seq <<
" ttl=" << response.
lifetime.
toString() <<
" time=" << tm << std::endl;
400 if (stop_after_first_fail)
403 std::cout <<
"Timeout." << std::endl;
406 if (interval_pause > 0)
409 __pause.
wait(interval_pause * 1000);
422 if (stop_after_first_fail)
424 std::cout <<
"No response, aborting." << std::endl;
431 std::cerr <<
"Disconnected." << std::endl;
433 std::cerr <<
"Error while receiving a bundle." << std::endl;
440 std::cerr <<
"Can not connect to the daemon. Does it run?" << std::endl;
442 }
catch (
const std::exception&) {
443 std::cerr <<
"unknown error" << std::endl;