Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #include "config.h"
00009 #include "ibrdtn/api/Client.h"
00010 #include "ibrdtn/api/StringBundle.h"
00011 #include "ibrcommon/net/tcpclient.h"
00012 #include "ibrcommon/thread/Mutex.h"
00013 #include "ibrcommon/thread/MutexLock.h"
00014 #include "ibrcommon/TimeMeasurement.h"
00015
00016 #include <algorithm>
00017 #include <iostream>
00018
00019 class Tracer : public dtn::api::Client
00020 {
00021 public:
00022 Tracer(dtn::api::Client::COMMUNICATION_MODE mode, string app, ibrcommon::tcpstream &stream)
00023 : dtn::api::Client(app, stream, mode), _stream(stream)
00024 {
00025 }
00026
00027 virtual ~Tracer()
00028 {
00029 }
00030
00031 void tracepath(const dtn::data::EID &destination)
00032 {
00033
00034 dtn::api::StringBundle b(destination);
00035
00036
00037 b.setLifetime(30);
00038
00039
00040 b.append("follow the white rabbit");
00041
00042
00043 b.requestDeliveredReport();
00044 b.requestForwardedReport();
00045 b.requestDeletedReport();
00046
00047 b.setReportTo( EID("api:me") );
00048
00049 ibrcommon::TimeMeasurement tm;
00050
00051 std::list<dtn::api::Bundle> bundles;
00052
00053 try {
00054
00055 tm.start();
00056
00057
00058 (*this) << b << std::flush;
00059
00060 try {
00061
00062 while (true)
00063 {
00064 dtn::api::Bundle recv = getBundle(10);
00065 bundles.push_back(recv);
00066 tm.stop();
00067
00068 std::cout << "Report received after " << tm << std::endl;
00069 }
00070 } catch (const std::exception&) {
00071
00072 }
00073
00074 std::cout << "No more reports received." << std::endl;
00075
00076
00077 bundles.sort();
00078
00079
00080 for (std::list<dtn::api::Bundle>::iterator iter = bundles.begin(); iter != bundles.end(); iter++)
00081 {
00082 std::cout << "Hop: " << (*iter).getSource().getString() << std::endl;
00083 }
00084
00085 } catch (const dtn::api::ConnectionException&) {
00086 cout << "Disconnected." << endl;
00087 } catch (const ibrcommon::IOException&) {
00088 cout << "Error while receiving a bundle." << endl;
00089 }
00090 }
00091
00092 private:
00093 ibrcommon::tcpstream &_stream;
00094 };
00095
00096 void print_help()
00097 {
00098 cout << "-- dtntracepath (IBR-DTN) --" << endl;
00099 cout << "Syntax: dtntracepath [options] <dst>" << endl;
00100 cout << " <dst> set the destination eid (e.g. dtn://node/echo)" << endl;
00101 cout << "* optional parameters *" << endl;
00102 cout << " -h|--help display this text" << endl;
00103
00104
00105
00106
00107
00108
00109 }
00110
00111 int main(int argc, char *argv[])
00112 {
00113 std::string trace_destination = "dtn://local";
00114 std::string trace_source = "tracepath";
00115 dtn::api::Client::COMMUNICATION_MODE mode = dtn::api::Client::MODE_BIDIRECTIONAL;
00116
00117 if (argc == 1)
00118 {
00119 print_help();
00120 return 0;
00121 }
00122
00123 for (int i = 0; i < argc; i++)
00124 {
00125 string arg = argv[i];
00126
00127
00128 if (arg == "-h" || arg == "--help")
00129 {
00130 print_help();
00131 return 0;
00132 }
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164 }
00165
00166
00167 trace_destination = argv[argc - 1];
00168
00169 try {
00170
00171 ibrcommon::tcpclient conn("127.0.0.1", 4550);
00172
00173
00174 conn.enableNoDelay();
00175
00176
00177 Tracer tracer(mode, trace_source, conn);
00178
00179
00180
00181 tracer.connect();
00182
00183
00184 tracer.tracepath(trace_destination);
00185
00186
00187 tracer.close();
00188 conn.close();
00189
00190 } catch (const ibrcommon::tcpclient::SocketException&) {
00191 cerr << "Can not connect to the daemon. Does it run?" << endl;
00192 return -1;
00193 } catch (...) {
00194
00195 }
00196
00197 return 0;
00198 }