Prophet.h

Go to the documentation of this file.
00001 #ifndef _DTN_PROPHET_ALGORITHM_
00002 #define _DTN_PROPHET_ALGORITHM_
00003 
00004 // pages and paragraphs refer to IETF Prophet, March 2006
00005 
00006 namespace dtn {
00007 
00008 class Prophet {
00009 public:
00010 
00011     // default initialization values, p. 15, 3.3, figure 2
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     // Strategy defaults are arbitrary; others are as defined by Prophet
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     // p. 9, 2.1.1, equation 1
00036     double delivery_predictability(double previous) {
00037         ASSERT(previous >= 0.0 && previous <= 1.0);
00038         return (previous + (1.0 - previous) * encounter_);
00039     }
00040 
00041     // p. 9, 2.1.1, equation 2
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     // p. 10, 2.1.1, equation 3
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     // p. 18, 3.7, equation 7
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     // forwarding strategies
00077     // p. 17, 3.6
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     // queuing strategies
00088     // p. 18, 3.7
00089     typedef enum {
00090         FIFO,
00091         MOFO,
00092         MOPR,
00093         LINEAR_MOPR,
00094         SHLI,
00095         LEPR
00096     } q_strategy_t;
00097 
00098     // XXX/wilson Endian-ness beware!!
00099     //   all of the below should be audited and rewritten
00100     //   to be cross-platform-friendly
00101 
00102     // Header Definition
00103     // p. 21, 4.2
00104     struct ProphetHeader {
00105         u_int8_t version; // defined as 0x01
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     // Legal values for ProphetHeader.result field
00118     // p. 22, 4.2
00119     typedef enum {
00120         NoSuccessAck  = 0x1,
00121         AckAll        = 0x2,
00122         Success       = 0x3,
00123         Failure       = 0x4,
00124         ReturnReceipt = 0x5
00125     } header_result_t;
00126 
00127     // Hello TLV header
00128     // p. 25, 4.4.1
00129     struct HelloTLVHeader {
00130         u_int8_t type; // defined as 0x01
00131         u_int8_t unused__:5;
00132         u_int8_t HF:3;
00133         u_int16_t length;
00134         u_int8_t timer; // units of 100ms
00135         u_int8_t name_length;
00136         u_char sender_name[0];
00137     } __attribute__((packed));
00138 
00139     // Legal values for HelloTLVHeader.HF (hello function)
00140     // p. 25, 4.4.1
00141     typedef enum {
00142         SYN         = 0x1,
00143         SYNACK      = 0x2,
00144         ACK         = 0x3,
00145         RSTACK      = 0x4
00146     } hello_hf_t;
00147 
00148     // Error TLV header
00149     // p. 26, 4.4.2
00150     struct ErrorTLVHeader {
00151         u_int8_t type; // defined as 0x02
00152         u_int8_t flags; // TBD
00153         u_int16_t length;
00154     } __attribute__((packed));
00155 
00156     // Routing Information Base Dictionary TLV
00157     // p. 27, 4.4.3
00158     struct RIBDTLVHeader {
00159         u_int8_t type; // defined as 0xA0
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     // Routing Address String (entry in RIBD above)
00167     // p. 27, 4.4.3
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     // Routing Information Base TLV
00176     // p. 28, 4.4.4
00177     struct RIBTLVHeader {
00178         u_int8_t type; // defined as 0xA1
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     // RIB Header Flags
00186     // p. 28, 4.4.4
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     // Routing Information Base entry
00194     // p. 28, 4.4.4
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     // RIB Entry Flags
00202     // p. 28, 4.4.4
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     // Bundle Offer/Response Header
00210     // p. 30, 4.4.5
00211     struct BundleOfferResponseHeader {
00212         u_int8_t type; // defined as 0xA2
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     // Bundle Offer/Response Entry
00220     // p. 30, 4.4.5
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     // BundleOffer flag values
00229     // p. 31, 4.4.5
00230     typedef enum {
00231         CUSTODY_OFFERED = 1 << 0,
00232         PROPHET_ACK     = 1 << 7
00233     } bundle_offer_flags_t;
00234 
00235     // BundleResponse flag values
00236     // p. 31, 4.4.5
00237     typedef enum {
00238         CUSTODY_ACCEPTED = 1 << 0,
00239         BUNDLE_ACCEPTED  = 1 << 1
00240     } bundle_response_flags_t;
00241 
00242     // accessors
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     // mutators
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 }; // Prophet
00300 
00321 class ProphetTable 
00322 {
00323 public:
00324     ProphetTable();
00325     ~ProphetTable();
00326 }; // ProphetTable
00327 
00328 }; // dtn
00329 
00330 #endif // _DTN_PROPHET_ALGORITHM_

Generated on Fri Dec 22 14:48:00 2006 for DTN Reference Implementation by  doxygen 1.5.1