00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifdef HAVE_CONFIG_H
00018 #include <dtn-config.h>
00019 #endif
00020
00021 #include <oasys/io/FileIOClient.h>
00022 #include "bundling/Bundle.h"
00023 #include "Node.h"
00024 #include "SimLog.h"
00025 #include "Simulator.h"
00026
00027 namespace dtnsim {
00028
00029 template <>
00030 SimLog* oasys::Singleton<SimLog>::instance_ = NULL;
00031
00032
00033
00034 SimLog::SimLog()
00035 {
00036 file_ = new oasys::FileIOClient();
00037 int err = 0;
00038 if (file_->open("./dtnsim_log.txt",
00039 O_CREAT | O_RDWR | O_TRUNC, 0644, &err) < 0) {
00040 log_crit_p("/dtn/sim/log",
00041 "ERROR opening sim log file: %s", strerror(err));
00042 }
00043 }
00044
00045
00046 void
00047 SimLog::flush()
00048 {
00049 file_->close();
00050 }
00051
00052
00053 void
00054 SimLog::log_entry(const char* what, Node* node, Bundle* bundle)
00055 {
00056 u_int32_t now = BundleTimestamp::get_current_time();
00057
00058 buf_.appendf("%f\t%s\t%s\t%s\t%s\t%u,%u\t%zu\t%u\n",
00059 Simulator::time(),
00060 node->name(),
00061 what,
00062 bundle->source().c_str(),
00063 bundle->dest().c_str(),
00064 bundle->creation_ts().seconds_,
00065 bundle->creation_ts().seqno_,
00066 bundle->payload().length(),
00067 now - bundle->creation_ts().seconds_);
00068
00069 file_->write(buf_.data(), buf_.length());
00070 buf_.trim(buf_.length());
00071 }
00072
00073 }