00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "Decider.h"
00018
00019 #define LOG(_args...) if (core_ != NULL) core_->print_log("decider", \
00020 BundleCore::LOG_DEBUG, _args)
00021
00022 namespace prophet
00023 {
00024
00025 FwdDeciderGRTR::FwdDeciderGRTR(FwdStrategy::fwd_strategy_t fs,
00026 const Link* nexthop,
00027 BundleCore* core,
00028 const Table* local,
00029 const Table* remote,
00030 const Stats* stats,
00031 bool relay)
00032 : Decider(fs,nexthop,core,local,remote,stats,relay) {}
00033
00034 bool
00035 FwdDeciderGRTR::operator()(const Bundle* b) const
00036 {
00037
00038 if (b == NULL) return false;
00039
00040
00041 if (!core_->should_fwd(b,next_hop_))
00042 {
00043 LOG("core declined to fwd %s %u:%u",
00044 b->destination_id().c_str(),
00045 b->creation_ts(), b->sequence_num());
00046 return false;
00047 }
00048
00049 if (core_->is_route(b->destination_id(),next_hop_->remote_eid()))
00050 {
00051 LOG("ok to fwd: %s is destination for bundle %s %u:%u",
00052 next_hop_->remote_eid(),b->destination_id().c_str(),
00053 b->creation_ts(),b->sequence_num());
00054 return true;
00055 }
00056
00057
00058 else if (!is_relay_)
00059 return false;
00060
00061 std::string dest_eid = core_->get_route(b->destination_id());
00062
00063 if (local_->p_value(dest_eid) < remote_->p_value(dest_eid))
00064 {
00065 LOG("ok to fwd: %s is better route for bundle %s %u:%u "
00066 "(%.2f > %.2f)", next_hop_->remote_eid(),b->destination_id().c_str(),
00067 b->creation_ts(),b->sequence_num(),
00068 remote_->p_value(b), local_->p_value(b));
00069 return true;
00070 }
00071
00072
00073 return false;
00074 }
00075
00076 FwdDeciderGTMX::FwdDeciderGTMX(FwdStrategy::fwd_strategy_t fs,
00077 const Link* nexthop,
00078 BundleCore* core,
00079 const Table* local,
00080 const Table* remote,
00081 u_int max_fwd,
00082 bool relay)
00083 : FwdDeciderGRTR(fs,nexthop,core,local,remote,NULL,relay),
00084 max_fwd_(max_fwd) {}
00085
00086 bool
00087 FwdDeciderGTMX::operator()(const Bundle* b) const
00088 {
00089
00090 if (! FwdDeciderGRTR::operator()(b))
00091 return false;
00092
00093 if (core_->is_route(b->destination_id(),next_hop_->nexthop()))
00094 {
00095 LOG("ok to fwd: %s is destination for bundle %s %u:%u",
00096 next_hop_->remote_eid(),b->destination_id().c_str(),
00097 b->creation_ts(),b->sequence_num());
00098 return true;
00099 }
00100
00101
00102 else if (!is_relay_)
00103 return false;
00104
00105
00106 if (b->num_forward() < max_fwd_)
00107 {
00108 LOG("ok to fwd: num_fwd(bundle %s %u:%u) == %u, max == %u",
00109 b->destination_id().c_str(), b->creation_ts(),b->sequence_num(),
00110 b->num_forward(), max_fwd_);
00111 return true;
00112 }
00113
00114
00115 return false;
00116 }
00117
00118 FwdDeciderGRTRPLUS::FwdDeciderGRTRPLUS(FwdStrategy::fwd_strategy_t fs,
00119 const Link* nexthop,
00120 BundleCore* core,
00121 const Table* local,
00122 const Table* remote,
00123 const Stats* stats,
00124 bool relay)
00125 : FwdDeciderGRTR(fs,nexthop,core,local,remote,stats,relay) {}
00126
00127 bool
00128 FwdDeciderGRTRPLUS::operator()(const Bundle* b) const
00129 {
00130
00131 if (! FwdDeciderGRTR::operator()(b))
00132 return false;
00133
00134 if (core_->is_route(b->destination_id(),next_hop_->nexthop()))
00135 {
00136 LOG("ok to fwd: %s is destination for bundle %s %u:%u",
00137 next_hop_->remote_eid(),b->destination_id().c_str(),
00138 b->creation_ts(),b->sequence_num());
00139 return true;
00140 }
00141
00142
00143 else if (!is_relay_)
00144 return false;
00145
00146
00147 bool ok = stats_->get_p_max(b) < remote_->p_value(b);
00148 if (ok)
00149 LOG("ok to fwd: remote p (%.2f) greater than max p (%.2f) for "
00150 "%s %u:%u", remote_->p_value(b), stats_->get_p_max(b),
00151 b->destination_id().c_str(), b->creation_ts(),
00152 b->sequence_num());
00153 return ok;
00154 }
00155
00156 FwdDeciderGTMXPLUS::FwdDeciderGTMXPLUS(FwdStrategy::fwd_strategy_t fs,
00157 const Link* nexthop,
00158 BundleCore* core,
00159 const Table* local,
00160 const Table* remote,
00161 const Stats* stats,
00162 u_int max_forward,
00163 bool relay)
00164 : FwdDeciderGRTRPLUS(fs,nexthop,core,local,remote,stats,relay),
00165 max_fwd_(max_forward) {}
00166
00167 bool
00168 FwdDeciderGTMXPLUS::operator()(const Bundle* b) const
00169 {
00170
00171 if (! FwdDeciderGRTRPLUS::operator()(b))
00172 return false;
00173
00174 if (core_->is_route(b->destination_id(),next_hop_->nexthop()))
00175 {
00176 LOG("ok to fwd: %s is destination for bundle %s %u:%u",
00177 next_hop_->remote_eid(),b->destination_id().c_str(),
00178 b->creation_ts(),b->sequence_num());
00179 return true;
00180 }
00181
00182
00183
00184 else if (!is_relay_)
00185 return false;
00186
00187 bool num_fwd_ok = b->num_forward() < max_fwd_;
00188 bool p_max_ok = stats_->get_p_max(b) < remote_->p_value(b);
00189
00190 if (num_fwd_ok && p_max_ok)
00191 LOG("ok to fwd: NF (%u) < maxNF (%u) and remote p (%.2f) > "
00192 "max (%.2f) for %s %u:%u",b->num_forward(), max_fwd_,
00193 remote_->p_value(b), stats_->get_p_max(b),
00194 b->destination_id().c_str(), b->creation_ts(),
00195 b->sequence_num());
00196
00197 return num_fwd_ok && p_max_ok;
00198 }
00199
00200 };