00001 #ifndef _DTN_PROPHET_ALGORITHM_
00002 #define _DTN_PROPHET_ALGORITHM_
00003
00004
00005
00006 namespace dtn {
00007
00008 class Prophet {
00009 public:
00010
00011
00012 static const double DEFAULT_P_ENCOUNTER = 0.75;
00013 static const double DEFAULT_PROPHET_BETA = 0.25;
00014 static const double DEFAULT_PROPHET_GAMMA = 0.25;
00015
00019 static const u_int8_t PROPHET_VERSION = 0x01;
00020
00021
00022 Prophet()
00023 : encounter_(DEFAULT_P_ENCOUNTER),
00024 beta_(DEFAULT_PROPHET_BETA),
00025 gamma_(DEFAULT_PROPHET_GAMMA),
00026 f_strategy(GRTR),
00027 q_strategy(FIFO)
00028 {
00029 }
00030
00031
00036 double delivery_predictability(double previous) {
00037 ASSERT(previous >= 0.0 && previous <= 1.0);
00038 return (previous + (1.0 - previous) * encounter_);
00039 }
00040
00041
00046 double age(double previous, u_int time_units) {
00047 ASSERT(previous >= 0.0 && previous <= 1.0);
00048 ASSERT(time_units > 0);
00049 return (previous * pow( gamma_, time_units+0.0));
00050 }
00051
00052
00057 double transitivity(double previous, double ab, double bc) {
00058 ASSERT(previous >= 0.0 && previous <= 1.0);
00059 ASSERT(ab >= 0.0 && ab <= 1.0);
00060 ASSERT(bc >= 0.0 && bc <= 1.0);
00061 return (previous + (1 - previous) * ab * bc * beta_);
00062 }
00063
00064
00070 double favorability(double previous, double prob) {
00071 ASSERT(previous >= 0.0 && previous <= 1.0);
00072 ASSERT(prob >= 0.0 && prob <= 1.0);
00073 return (previous + (1 - previous) * prob);
00074 }
00075
00076
00077
00078 typedef enum {
00079 GRTR,
00080 GTMX,
00081 GRTR_PLUS,
00082 GTMX_PLUS,
00083 GRTR_SORT,
00084 GRTR_MAX
00085 } fwd_strategy_t;
00086
00087
00088
00089 typedef enum {
00090 FIFO,
00091 MOFO,
00092 MOPR,
00093 LINEAR_MOPR,
00094 SHLI,
00095 LEPR
00096 } q_strategy_t;
00097
00098
00099
00100
00101
00102
00103
00104 struct ProphetHeader {
00105 u_int8_t version;
00106 u_int8_t flags;
00107 u_int8_t result;
00108 u_int8_t code;
00109 u_int16_t receiver_instance;
00110 u_int16_t sender_instance;
00111 u_int32_t transaction_id;
00112 u_int16_t submessage_flag:1;
00113 u_int16_t submessage_num:15;
00114 u_int16_t length;
00115 } __attribute__((packed));
00116
00117
00118
00119 typedef enum {
00120 NoSuccessAck = 0x1,
00121 AckAll = 0x2,
00122 Success = 0x3,
00123 Failure = 0x4,
00124 ReturnReceipt = 0x5
00125 } header_result_t;
00126
00127
00128
00129 struct HelloTLVHeader {
00130 u_int8_t type;
00131 u_int8_t unused__:5;
00132 u_int8_t HF:3;
00133 u_int16_t length;
00134 u_int8_t timer;
00135 u_int8_t name_length;
00136 u_char sender_name[0];
00137 } __attribute__((packed));
00138
00139
00140
00141 typedef enum {
00142 SYN = 0x1,
00143 SYNACK = 0x2,
00144 ACK = 0x3,
00145 RSTACK = 0x4
00146 } hello_hf_t;
00147
00148
00149
00150 struct ErrorTLVHeader {
00151 u_int8_t type;
00152 u_int8_t flags;
00153 u_int16_t length;
00154 } __attribute__((packed));
00155
00156
00157
00158 struct RIBDTLVHeader {
00159 u_int8_t type;
00160 u_int8_t flags;
00161 u_int16_t length;
00162 u_int16_t ribd_entry_count;
00163 u_int16_t unused__;
00164 } __attribute__((packed));
00165
00166
00167
00168 struct RoutingAddressString {
00169 u_int16_t string_id;
00170 u_int8_t length;
00171 u_int8_t unused__;
00172 u_char ra_string[0];
00173 } __attribute__((packed));
00174
00175
00176
00177 struct RIBTLVHeader {
00178 u_int8_t type;
00179 u_int8_t flags;
00180 u_int16_t length;
00181 u_int16_t rib_string_count;
00182 u_int16_t unused__;
00183 } __attribute__((packed));
00184
00185
00186
00187 typedef enum {
00188 RELAY_NODE = 1 << 0,
00189 CUSTODY_NODE = 1 << 1,
00190 INTERNET_GW_NODE = 1 << 2
00191 } rib_header_flag_t;
00192
00193
00194
00195 struct RIBEntry {
00196 u_int16_t ribd_string_id;
00197 u_int8_t pvalue;
00198 u_int8_t flags;
00199 } __attribute__((packed));
00200
00201
00202
00203 typedef enum {
00204 RELAY_NODE = 1 << 0,
00205 CUSTODY_NODE = 1 << 1,
00206 INTERNET_GW_NODE = 1 << 2
00207 } rib_entry_flag_t;
00208
00209
00210
00211 struct BundleOfferResponseHeader {
00212 u_int8_t type;
00213 u_int8_t flags;
00214 u_int16_t length;
00215 u_int16_t bundle_offer_count;
00216 u_int16_t unused__;
00217 } __attribute__((packed));
00218
00219
00220
00221 struct BundleOfferResponseEntry {
00222 u_int16_t bundle_dest_string_id;
00223 u_int8_t b_flags;
00224 u_int8_t unused__;
00225 u_int32_t creation_timestamp;
00226 } __attribute__((packed));
00227
00228
00229
00230 typedef enum {
00231 CUSTODY_OFFERED = 1 << 0,
00232 PROPHET_ACK = 1 << 7
00233 } bundle_offer_flags_t;
00234
00235
00236
00237 typedef enum {
00238 CUSTODY_ACCEPTED = 1 << 0,
00239 BUNDLE_ACCEPTED = 1 << 1
00240 } bundle_response_flags_t;
00241
00242
00243 double encounter() { return encounter_; }
00244 double beta() { return beta_; }
00245 double gamma() { return gamma_; }
00246 fwd_strategy_t fwd_strategy() { return f_strategy_; }
00247 q_strategy_t q_strategy() { return q_strategy_; }
00248
00249
00250 bool encounter( double d ) {
00251 if ( d >= 0.0 && d <= 1.0 ) {
00252 encounter_ = d;
00253 return true;
00254 }
00255 return false;
00256 }
00257 bool beta( double d ) {
00258 if ( d >= 0.0 && d <= 1.0 ) {
00259 beta_ = d;
00260 return true;
00261 }
00262 return false;
00263 }
00264 bool gamma( double d ) {
00265 if ( d >= 0.0 && d <= 1.0 ) {
00266 gamma_ = d;
00267 return true;
00268 }
00269 return false;
00270 }
00271 void fwd_strategy( fwd_strategy_t f ) { f_strategy_ = f; }
00272 void q_strategy( q_strategy_t q ) { q_strategy_ = q; }
00273 protected:
00274 double encounter_;
00275 double beta_;
00276 double gamma_;
00277 fwd_strategy_t f_strategy_;
00278 q_strategy_t q_strategy_;
00279 };
00280
00284 class ProphetNode
00285 {
00286 public:
00290 class Params {
00291 public:
00292 double encounter_;
00293 double beta_;
00294 double gamma_;
00295 };
00296
00297 Prophet(EndpointID remote);
00298 ~Prophet();
00299 };
00300
00321 class ProphetTable
00322 {
00323 public:
00324 ProphetTable();
00325 ~ProphetTable();
00326 };
00327
00328 };
00329
00330 #endif // _DTN_PROPHET_ALGORITHM_