|
1 /* |
|
2 * Copyright 2007 Intel Corporation |
|
3 * |
|
4 * Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 * you may not use this file except in compliance with the License. |
|
6 * You may obtain a copy of the License at |
|
7 * |
|
8 * http://www.apache.org/licenses/LICENSE-2.0 |
|
9 * |
|
10 * Unless required by applicable law or agreed to in writing, software |
|
11 * distributed under the License is distributed on an "AS IS" BASIS, |
|
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
13 * See the License for the specific language governing permissions and |
|
14 * limitations under the License. |
|
15 */ |
|
16 |
|
17 #ifdef HAVE_CONFIG_H |
|
18 #include <dtn-config.h> |
|
19 #endif |
|
20 |
|
21 #include <oasys/io/FileIOClient.h> |
|
22 #include "bundling/Bundle.h" |
|
23 #include "Node.h" |
|
24 #include "SimLog.h" |
|
25 #include "Simulator.h" |
|
26 |
|
27 namespace dtnsim { |
|
28 |
|
29 template <> |
|
30 SimLog* oasys::Singleton<SimLog>::instance_ = NULL; |
|
31 |
|
32 |
|
33 //---------------------------------------------------------------------- |
|
34 SimLog::SimLog() |
|
35 { |
|
36 file_ = new oasys::FileIOClient(); |
|
37 int err = 0; |
|
38 if (file_->open("./dtnsim_log.txt", |
|
39 O_CREAT | O_RDWR | O_TRUNC, 0644, &err) < 0) { |
|
40 log_crit_p("/dtn/sim/log", |
|
41 "ERROR opening sim log file: %s", strerror(err)); |
|
42 } |
|
43 } |
|
44 |
|
45 //---------------------------------------------------------------------- |
|
46 void |
|
47 SimLog::flush() |
|
48 { |
|
49 file_->close(); |
|
50 } |
|
51 |
|
52 //---------------------------------------------------------------------- |
|
53 void |
|
54 SimLog::log_entry(const char* what, Node* node, Bundle* bundle) |
|
55 { |
|
56 u_int64_t now = BundleTimestamp::get_current_time(); |
|
57 |
|
58 buf_.appendf("%f\t%s\t%s\t%s\t%s\t%llu,%llu\t%zu\t%llu\n", |
|
59 Simulator::time(), |
|
60 node->name(), |
|
61 what, |
|
62 bundle->source().c_str(), |
|
63 bundle->dest().c_str(), |
|
64 bundle->creation_ts().seconds_, |
|
65 bundle->creation_ts().seqno_, |
|
66 bundle->payload().length(), |
|
67 now - bundle->creation_ts().seconds_); |
|
68 |
|
69 file_->write(buf_.data(), buf_.length()); |
|
70 buf_.trim(buf_.length()); |
|
71 } |
|
72 |
|
73 } // namespace dtnsim |