00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #include <oasys/thread/SpinLock.h>
00040 #include <oasys/util/StringBuffer.h>
00041 #include "conv_layers/ConvergenceLayer.h"
00042 #include "contacts/Link.h"
00043 #include "ForwardingLog.h"
00044
00045 namespace dtn {
00046
00047
00048 ForwardingLog::ForwardingLog(oasys::SpinLock* lock)
00049 : lock_(lock)
00050 {
00051 }
00052
00053
00054 bool
00055 ForwardingLog::get_latest_entry(Link* link, ForwardingInfo* info) const
00056 {
00057 oasys::ScopeLock l(lock_, "ForwardingLog::get_latest_state");
00058
00059 Log::const_reverse_iterator iter;
00060 for (iter = log_.rbegin(); iter != log_.rend(); ++iter)
00061 {
00062 if (iter->nexthop_ == link->nexthop() &&
00063 iter->clayer_ == link->clayer()->name())
00064 {
00065 *info = *iter;
00066 return true;
00067 }
00068 }
00069
00070 return false;
00071 }
00072
00073
00074 ForwardingLog::state_t
00075 ForwardingLog::get_latest_entry(Link* link) const
00076 {
00077 ForwardingInfo info;
00078 if (! get_latest_entry(link, &info)) {
00079 return ForwardingInfo::NONE;
00080 }
00081
00082 return info.state_;
00083 }
00084
00085
00086 size_t
00087 ForwardingLog::get_transmission_count(ForwardingInfo::action_t action,
00088 bool include_inflight) const
00089 {
00090 size_t ret = 0;
00091
00092 oasys::ScopeLock l(lock_, "ForwardingLog::get_transmission_count");
00093
00094 Log::const_iterator iter;
00095 for (iter = log_.begin(); iter != log_.end(); ++iter)
00096 {
00097 if (iter->state_ == ForwardingInfo::TRANSMITTED ||
00098 (include_inflight && (iter->state_ == ForwardingInfo::IN_FLIGHT)))
00099 {
00100 if ((action == iter->action_) ||
00101 (action == ForwardingInfo::INVALID_ACTION))
00102 {
00103 ++ret;
00104 }
00105 }
00106 }
00107
00108 return ret;
00109 }
00110
00111
00112 size_t
00113 ForwardingLog::get_count(state_t state) const
00114 {
00115 size_t ret = 0;
00116
00117 oasys::ScopeLock l(lock_, "ForwardingLog::get_count");
00118
00119 Log::const_iterator iter;
00120 for (iter = log_.begin(); iter != log_.end(); ++iter)
00121 {
00122 if (iter->state_ == state) {
00123 ++ret;
00124 }
00125 }
00126
00127 return ret;
00128 }
00129
00130
00131 void
00132 ForwardingLog::dump(oasys::StringBuffer* buf) const
00133 {
00134 oasys::ScopeLock l(lock_, "ForwardingLog::dump");
00135 buf->appendf("forwarding log:\n");
00136 Log::const_iterator iter;
00137 for (iter = log_.begin(); iter != log_.end(); ++iter)
00138 {
00139 const ForwardingInfo* info = &(*iter);
00140
00141 buf->appendf("\t%s -> %s %u.%u [%s cl:%s] [custody min %d pct %d max %d]\n",
00142 ForwardingInfo::state_to_str(info->state_),
00143 info->clayer_.c_str(),
00144 (u_int)info->timestamp_.tv_sec,
00145 (u_int)info->timestamp_.tv_usec,
00146 ForwardingInfo::action_to_str(info->action_),
00147 info->nexthop_.c_str(),
00148 info->custody_timer_.min_,
00149 info->custody_timer_.lifetime_pct_,
00150 info->custody_timer_.max_);
00151 }
00152 }
00153
00154
00155 void
00156 ForwardingLog::add_entry(Link* link,
00157 ForwardingInfo::action_t action,
00158 state_t state,
00159 const CustodyTimerSpec& custody_timer)
00160 {
00161 log_.push_back(ForwardingInfo(state, action, link->clayer()->name(),
00162 link->nexthop(), custody_timer));
00163 }
00164
00165
00166 bool
00167 ForwardingLog::update(Link* link, state_t state)
00168 {
00169 oasys::ScopeLock l(lock_, "ForwardingLog::update");
00170
00171 Log::reverse_iterator iter;
00172 for (iter = log_.rbegin(); iter != log_.rend(); ++iter)
00173 {
00174 if (iter->nexthop_ == link->nexthop() &&
00175 iter->clayer_ == link->clayer()->name())
00176 {
00177 iter->set_state(state);
00178 return true;
00179 }
00180 }
00181
00182 return false;
00183 }
00184
00185 }