00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _DTN_PROPHET_NODE_
00018 #define _DTN_PROPHET_NODE_
00019
00020 #include "routing/Prophet.h"
00021 #include <oasys/debug/Log.h>
00022 #include <oasys/util/Time.h>
00023 #include <oasys/util/URL.h>
00024 #include "naming/EndpointID.h"
00025 #include "bundling/BundleEvent.h"
00026
00027 #include <vector>
00028 #include <map>
00029 #include <set>
00030
00035 namespace dtn {
00036
00037 struct ProphetNodeParams
00038 {
00039 ProphetNodeParams()
00040 : encounter_(Prophet::DEFAULT_P_ENCOUNTER),
00041 beta_(Prophet::DEFAULT_BETA),
00042 gamma_(Prophet::DEFAULT_GAMMA),
00043 kappa_(Prophet::DEFAULT_KAPPA) {}
00044
00045 double encounter_;
00046 double beta_;
00047 double gamma_;
00048 u_int kappa_;
00049 };
00050
00054 class ProphetNode : public oasys::Logger
00055 {
00056 public:
00057
00058 ProphetNode(ProphetNodeParams* params = NULL,
00059 const char* logpath = "/dtn/route/prophet/node");
00060 ProphetNode(const ProphetNode& node);
00061
00062 virtual ~ProphetNode() {}
00063
00064 double p_value() const {return p_value_;}
00065 bool relay() const {return relay_;}
00066 bool custody() const {return custody_;}
00067 bool internet_gw() const {return internet_gateway_;}
00068 EndpointID remote_eid() const {return remote_eid_;}
00069 const oasys::Time& age() const {return age_;}
00070 bool route_to_me(const EndpointID& eid) const;
00071
00072 void set_eid( const EndpointID& eid ) { remote_eid_.assign(eid); }
00073 void set_pvalue( double d ) {
00074 if ( d >= 0.0 && d <= 1.0 ) p_value_ = d;
00075 }
00076 void set_relay( bool relay ) { relay_ = relay; }
00077 void set_custody( bool custody ) { custody_ = custody; }
00078 void set_internet_gw( bool gw ) { internet_gateway_ = gw; }
00079 void set_age( oasys::Time t ) {age_.sec_=t.sec_; age_.usec_=t.usec_;}
00080 void set_age_now() { age_.get_time(); }
00081
00082 ProphetNode& operator= (const ProphetNode& p) {
00083 p_value_ = p.p_value_;
00084 relay_ = p.relay_;
00085 custody_ = p.custody_;
00086 internet_gateway_ = p.internet_gateway_;
00087 remote_eid_.assign(p.remote_eid_);
00088 age_.sec_ = p.age_.sec_;
00089 age_.usec_ = p.age_.usec_;
00090 return *this;
00091 }
00092
00093 double encounter() const {return params_->encounter_;}
00094 double beta() const {return params_->beta_;}
00095 double gamma() const {return params_->gamma_;}
00096 u_int age_factor() const {return params_->kappa_;}
00101 void update_pvalue();
00102
00107 void update_transitive(double ab, double bc);
00108
00112 void update_age();
00113
00114 bool set_encounter( double d ) {
00115 if ( d >= 0.0 && d <= 1.0 ) { params_->encounter_ = d; return true; }
00116 return false;
00117 }
00118 bool set_beta( double d ) {
00119 if ( d >= 0.0 && d <= 1.0 ) { params_->beta_ = d; return true; }
00120 return false;
00121 }
00122 bool set_gamma( double d ) {
00123 if ( d >= 0.0 && d <= 1.0 ) { params_->gamma_ = d; return true; }
00124 return false;
00125 }
00126 void set_age_factor(u_int ms_per_unit) {
00127 params_->kappa_ = ms_per_unit;
00128 }
00129
00130 void dump(oasys::StringBuffer* buf);
00131
00132 protected:
00137 u_int time_to_units(oasys::Time diff);
00138
00139 ProphetNodeParams* params_;
00140 double p_value_;
00141 bool relay_;
00142 bool custody_;
00143 bool internet_gateway_;
00144 EndpointIDPattern remote_eid_;
00145 oasys::Time age_;
00146 };
00147
00148 class RIBNode : public ProphetNode
00149 {
00150 public:
00151 RIBNode(ProphetNode* node, u_int16_t sid)
00152 : ProphetNode(*node), sid_(sid)
00153 {}
00154 RIBNode(u_int16_t sid = 0)
00155 : ProphetNode(), sid_(sid)
00156 {}
00157 RIBNode(const RIBNode& a)
00158 : ProphetNode(a), sid_(a.sid_)
00159 {}
00160 virtual ~RIBNode()
00161 {}
00162 RIBNode& operator= (const RIBNode& a) {
00163 ProphetNode::operator=(a);
00164 sid_ = a.sid_;
00165 return *this;
00166 }
00167 void dump(oasys::StringBuffer* buf);
00168 u_int16_t sid_;
00169 };
00170
00171 #define BUNDLE_OFFER_LOGPATH "/dtn/route/prophet/bundleoffer"
00172
00175 class BundleOffer : public oasys::Logger
00176 {
00177 public:
00178 typedef enum {
00179 UNDEFINED = 0,
00180 OFFER,
00181 RESPONSE
00182 } bundle_offer_t;
00183
00184 static const char* type_to_str(bundle_offer_t type)
00185 {
00186 switch(type) {
00187 case OFFER: return "OFFER";
00188 case RESPONSE: return "RESPONSE";
00189 case UNDEFINED:
00190 default: break;
00191 }
00192 return "UNDEFINED";
00193 }
00194
00195 BundleOffer(bundle_offer_t type = UNDEFINED)
00196 : oasys::Logger("BundleOffer",BUNDLE_OFFER_LOGPATH),
00197 cts_(0), sid_(0),
00198 custody_(false), accept_(false), ack_(false),
00199 type_(type)
00200 {}
00201
00202 BundleOffer(const BundleOffer& b)
00203 : oasys::Logger("BundleOffer",BUNDLE_OFFER_LOGPATH),
00204 cts_(b.cts_), sid_(b.sid_), custody_(b.custody_),
00205 accept_(b.accept_), ack_(b.ack_),
00206 type_(b.type_)
00207 {
00208 ASSERTF((type_ == OFFER) || (type_ == RESPONSE),
00209 "type_==%d",(int)type_);
00210 }
00211
00212 BundleOffer(u_int32_t cts, u_int16_t sid, bool custody=false,
00213 bool accept=false, bool ack=false,
00214 bundle_offer_t type=UNDEFINED)
00215 : oasys::Logger("BundleOffer",BUNDLE_OFFER_LOGPATH),
00216 cts_(cts), sid_(sid),
00217 custody_(custody), accept_(accept), ack_(ack),
00218 type_(type)
00219 {
00220 ASSERTF((type_ == OFFER) || (type_ == RESPONSE),
00221 "type_==%d",(int)type_);
00222 }
00223
00224 BundleOffer& operator= (const BundleOffer& b) {
00225 cts_ = b.cts_;
00226 sid_ = b.sid_;
00227 custody_ = b.custody_;
00228 accept_ = b.accept_;
00229 ack_ = b.ack_;
00230 type_ = b.type_;
00231 ASSERTF((type_ == OFFER) || (type_ == RESPONSE),
00232 "type_==%d",(int)type_);
00233 return *this;
00234 }
00235
00236 bool operator< (const BundleOffer& b) const {
00237 if (sid_ == b.sid_)
00238 return (cts_ < b.cts_);
00239 return (sid_ < b.sid_);
00240 }
00241
00242 u_int32_t creation_ts() const { return cts_; }
00243 u_int16_t sid() const { return sid_; }
00244 bool custody() const { return custody_; }
00245 bool accept() const { return accept_; }
00246 bool ack() const { return ack_; }
00247 bundle_offer_t type() const { return type_; }
00248
00249 void dump(oasys::StringBuffer* buf);
00250
00251 protected:
00252
00253 u_int32_t cts_;
00254 u_int16_t sid_;
00255 bool custody_;
00256 bool accept_;
00257 bool ack_;
00258 bundle_offer_t type_;
00259
00260 };
00261
00262 class ProphetAck {
00263 public:
00264 ProphetAck();
00265 ProphetAck(const EndpointID& eid,u_int32_t cts=0,u_int32_t ets=0);
00266 ProphetAck(const ProphetAck&);
00267
00268 ProphetAck& operator= (const ProphetAck&);
00269 bool operator< (const ProphetAck&) const;
00270
00271 EndpointID dest_id_;
00272 u_int32_t cts_;
00273 u_int32_t ets_;
00274 };
00275
00276 };
00277
00278 #endif // _DTN_PROPHET_NODE_