00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _PROPHET_DECIDER_H_
00018 #define _PROPHET_DECIDER_H_
00019
00020 #include "Bundle.h"
00021 #include "Link.h"
00022 #include "Stats.h"
00023 #include "FwdStrategy.h"
00024 #include "BundleCore.h"
00025
00026 namespace prophet
00027 {
00028
00033 class Decider
00034 {
00035 public:
00039 virtual ~Decider() {}
00040
00044 static inline Decider* decider(FwdStrategy::fwd_strategy_t fs,
00045 const Link* nexthop,
00046 BundleCore* core,
00047 const Table* local_nodes,
00048 const Table* remote_nodes,
00049 const Stats* stats = NULL,
00050 u_int max_forward = 0,
00051 bool is_relay = true);
00052
00057 virtual bool operator() (const Bundle*) const = 0;
00058
00060 FwdStrategy::fwd_strategy_t fwd_strategy() const { return fwd_strategy_; }
00061 const Link* nexthop() const { return next_hop_; }
00062 const BundleCore* core() const { return core_; }
00063 const Table* local_nodes() const { return local_; }
00064 const Table* remote_nodes() const { return remote_; }
00065 const Stats* stats() const { return stats_; }
00066 bool is_relay() const { return is_relay_; }
00068
00069 protected:
00073 Decider(FwdStrategy::fwd_strategy_t fs,
00074 const Link* nexthop,
00075 BundleCore* core,
00076 const Table* local, const Table* remote,
00077 const Stats* stats, bool is_relay)
00078 : fwd_strategy_(fs),
00079 next_hop_(nexthop),
00080 core_(core), local_(local), remote_(remote),
00081 stats_(stats), is_relay_(is_relay) {}
00082
00083 FwdStrategy::fwd_strategy_t fwd_strategy_;
00084 const Link* next_hop_;
00085 BundleCore* const core_;
00086 const Table* local_;
00087 const Table* remote_;
00088 const Stats* stats_;
00089 bool is_relay_;
00090
00091 };
00092
00097 class FwdDeciderGRTR : public Decider
00098 {
00099 public:
00103 virtual ~FwdDeciderGRTR() {}
00104
00108 bool operator() (const Bundle*) const;
00109
00110 protected:
00111 friend class Decider;
00112
00116 FwdDeciderGRTR(FwdStrategy::fwd_strategy_t fs,
00117 const Link* nexthop, BundleCore* core,
00118 const Table* local, const Table* remote,
00119 const Stats* stats = NULL,
00120 bool relay = true);
00121 };
00122
00127 class FwdDeciderGTMX : public FwdDeciderGRTR
00128 {
00129 public:
00133 virtual ~FwdDeciderGTMX() {}
00134
00138 bool operator() (const Bundle*) const;
00139
00141 u_int max_forward() const { return max_fwd_; }
00143 protected:
00144 friend class Decider;
00145
00149 FwdDeciderGTMX(FwdStrategy::fwd_strategy_t fs,
00150 const Link* nexthop, BundleCore* core,
00151 const Table* local, const Table* remote,
00152 u_int max_fwd, bool relay);
00153
00154 u_int max_fwd_;
00155 };
00156
00162 class FwdDeciderGRTRPLUS : public FwdDeciderGRTR
00163 {
00164 public:
00168 virtual ~FwdDeciderGRTRPLUS() {}
00169
00173 bool operator() (const Bundle*) const;
00174
00175 protected:
00176 friend class Decider;
00177
00181 FwdDeciderGRTRPLUS(FwdStrategy::fwd_strategy_t fs,
00182 const Link* nexthop, BundleCore* core,
00183 const Table* local, const Table* remote,
00184 const Stats* stats, bool relay);
00185
00186 };
00187
00193 class FwdDeciderGTMXPLUS : public FwdDeciderGRTRPLUS
00194 {
00195 public:
00199 virtual ~FwdDeciderGTMXPLUS() {}
00200
00204 bool operator() (const Bundle*) const;
00205
00207 u_int max_forward() const { return max_fwd_; }
00209 protected:
00210 friend class Decider;
00211
00215 FwdDeciderGTMXPLUS(FwdStrategy::fwd_strategy_t fs,
00216 const Link* nexthop, BundleCore* core,
00217 const Table* local, const Table* remote,
00218 const Stats* stats,
00219 u_int max_forward, bool relay);
00220
00221 u_int max_fwd_;
00222 };
00223
00224 Decider*
00225 Decider::decider(FwdStrategy::fwd_strategy_t fs,
00226 const Link* nexthop,
00227 BundleCore* core,
00228 const Table* local_nodes,
00229 const Table* remote_nodes,
00230 const Stats* stats,
00231 u_int max_forward,
00232 bool is_relay)
00233 {
00234 Decider* d = NULL;
00235
00236
00237 if (nexthop == NULL || nexthop->nexthop() == "") return NULL;
00238 if (local_nodes == NULL) return NULL;
00239 if (remote_nodes == NULL) return NULL;
00240
00241
00242 switch (fs)
00243 {
00244 case FwdStrategy::GRTR:
00245 case FwdStrategy::GRTR_SORT:
00246 case FwdStrategy::GRTR_MAX:
00247 {
00248 d = new FwdDeciderGRTR(fs,nexthop,core,local_nodes,
00249 remote_nodes,NULL,is_relay);
00250 break;
00251 }
00252 case FwdStrategy::GTMX:
00253 {
00254 if (max_forward == 0) return NULL;
00255 d = new FwdDeciderGTMX(fs,nexthop,core,local_nodes,
00256 remote_nodes,max_forward,
00257 is_relay);
00258 break;
00259 }
00260 case FwdStrategy::GRTR_PLUS:
00261 {
00262 if (stats == NULL) return NULL;
00263 d = new FwdDeciderGRTRPLUS(fs,nexthop,core,local_nodes,
00264 remote_nodes,stats,is_relay);
00265 break;
00266 }
00267 case FwdStrategy::GTMX_PLUS:
00268 {
00269 if (stats == NULL || max_forward == 0) return NULL;
00270 d = new FwdDeciderGTMXPLUS(fs,nexthop,core,local_nodes,
00271 remote_nodes,stats,max_forward,
00272 is_relay);
00273 break;
00274 }
00275 case FwdStrategy::INVALID_FS:
00276 default:
00277 break;
00278 }
00279 return d;
00280 }
00281
00282 };
00283
00284 #endif // _PROPHET_DECIDER_H_