IBR-DTNSuite
0.8
|
00001 #ifndef PROPHETROUTINGEXTENSION_H_ 00002 #define PROPHETROUTINGEXTENSION_H_ 00003 00004 #include "routing/BaseRouter.h" 00005 #include <ibrcommon/thread/Mutex.h> 00006 #include <ibrcommon/thread/Queue.h> 00007 #include <ibrcommon/thread/ThreadsafeReference.h> 00008 00009 #include <map> 00010 #include <list> 00011 00012 #define DISABLE_MAP_STORE 1 00013 00014 namespace dtn 00015 { 00016 namespace routing 00017 { 00028 class ProphetRoutingExtension : public BaseRouter::ThreadedExtension 00029 { 00030 public: 00031 00038 class DeliveryPredictabilityMap : public std::map<dtn::data::EID, float>, public NodeHandshakeItem, public ibrcommon::Mutex 00039 { 00040 public: 00041 /* virtual methods from NodeHandshakeItem */ 00042 00043 virtual size_t getIdentifier() const; 00044 virtual size_t getLength() const; 00045 virtual std::ostream& serialize(std::ostream& stream) const; 00046 virtual std::istream& deserialize(std::istream& stream); 00047 static const size_t identifier; 00048 00049 /* TODO: move this to a deserializer or toString? */ 00050 friend std::ostream& operator<<(ostream&, const DeliveryPredictabilityMap&); 00051 }; 00052 00056 class ForwardingStrategy 00057 { 00058 public: 00059 ForwardingStrategy(); 00060 virtual ~ForwardingStrategy() = 0; 00069 virtual bool shallForward(const dtn::data::EID& neighbor, const dtn::data::MetaBundle& bundle) const = 0; 00073 bool neighborDPIsGreater(const dtn::data::EID& neighbor, const dtn::data::EID& destination) const; 00074 00078 void setProphetRouter(ProphetRoutingExtension *router); 00079 00080 protected: 00081 ProphetRoutingExtension *_prophet_router; 00082 }; 00083 00088 class Acknowledgement 00089 { 00090 public: 00091 Acknowledgement(); 00092 Acknowledgement(const dtn::data::BundleID&, size_t expire_time); 00093 virtual ~Acknowledgement(); 00094 std::ostream& serialize(std::ostream& stream) const; 00095 std::istream& deserialize(std::istream& stream); 00096 00097 bool operator<(const Acknowledgement &other) const; 00098 00099 dtn::data::BundleID bundleID; 00100 size_t expire_time; 00101 }; 00102 00106 class AcknowledgementSet : public NodeHandshakeItem, public ibrcommon::Mutex 00107 { 00108 public: 00109 AcknowledgementSet(); 00110 AcknowledgementSet(const AcknowledgementSet&); 00111 00112 void insert(const Acknowledgement&); 00113 void purge(); 00114 void merge(const AcknowledgementSet&); 00115 bool has(const dtn::data::BundleID &bundle) const; 00116 00117 /* virtual methods from NodeHandshakeItem */ 00118 virtual size_t getIdentifier() const; 00119 virtual size_t getLength() const; 00120 virtual std::ostream& serialize(std::ostream& stream) const; 00121 virtual std::istream& deserialize(std::istream& stream); 00122 static const size_t identifier; 00123 00124 /* TODO: move this to a deserializer or toString? */ 00125 friend std::ostream& operator<<(ostream&, const AcknowledgementSet&); 00126 private: 00127 std::set<Acknowledgement> _ackSet; 00128 }; 00129 00130 ProphetRoutingExtension(ForwardingStrategy *strategy, float p_encounter_max, float p_encounter_first, 00131 float p_first_threshold, float beta, float gamma, float delta, 00132 size_t time_unit, size_t i_typ, 00133 size_t next_exchange_timeout); 00134 virtual ~ProphetRoutingExtension(); 00135 00136 /* virtual methods from BaseRouter::Extension */ 00137 virtual void requestHandshake(const dtn::data::EID&, NodeHandshake&) const; 00138 virtual void responseHandshake(const dtn::data::EID&, const NodeHandshake&, NodeHandshake&); 00139 virtual void processHandshake(const dtn::data::EID&, NodeHandshake&); 00140 virtual void notify(const dtn::core::Event *evt); 00141 00147 ibrcommon::ThreadsafeReference<DeliveryPredictabilityMap> getDeliveryPredictabilityMap(); 00153 ibrcommon::ThreadsafeReference<const DeliveryPredictabilityMap> getDeliveryPredictabilityMap() const; 00154 00159 ibrcommon::ThreadsafeReference<const AcknowledgementSet> getAcknowledgementSet() const; 00160 protected: 00161 virtual void run(); 00162 void __cancellation(); 00163 private: 00170 void update(const DeliveryPredictabilityMap& neighbor_dp_map, const dtn::data::EID& neighbor); 00171 00176 void updateNeighbor(const dtn::data::EID& neighbor); 00177 00182 void age(); 00183 00184 DeliveryPredictabilityMap _deliveryPredictabilityMap; 00185 ForwardingStrategy *_forwardingStrategy; 00186 AcknowledgementSet _acknowledgementSet; 00187 00188 #ifndef DISABLE_MAP_STORE 00189 typedef std::map<dtn::data::EID, DeliveryPredictabilityMap> map_store; 00195 map_store _mapStore; 00196 #endif 00197 00198 ibrcommon::Mutex _next_exchange_mutex; 00199 size_t _next_exchange_timeout; 00200 size_t _next_exchange_timestamp; 00201 00205 float p_encounter(const dtn::data::EID &neighbor) const; 00206 00207 float _p_encounter_max; 00208 float _p_encounter_first; 00209 float _p_first_threshold; 00210 float _beta; 00211 float _gamma; 00212 float _delta; 00213 size_t _lastAgingTime; 00214 size_t _time_unit; 00215 size_t _i_typ; 00216 00217 typedef std::map<dtn::data::EID, size_t> age_map; 00218 age_map _ageMap; 00219 00220 class Task 00221 { 00222 public: 00223 virtual ~Task() {}; 00224 virtual std::string toString() const = 0; 00225 }; 00226 00227 class SearchNextBundleTask : public Task 00228 { 00229 public: 00230 SearchNextBundleTask(const dtn::data::EID &eid); 00231 virtual ~SearchNextBundleTask(); 00232 00233 virtual std::string toString() const; 00234 00235 const dtn::data::EID eid; 00236 }; 00237 00238 class NextExchangeTask : public Task 00239 { 00240 public: 00241 NextExchangeTask(); 00242 virtual ~NextExchangeTask(); 00243 00244 virtual std::string toString() const; 00245 }; 00246 00247 ibrcommon::Queue<Task* > _taskqueue; 00248 00249 public: 00255 class GRTR_Strategy : public ForwardingStrategy 00256 { 00257 public: 00258 explicit GRTR_Strategy(); 00259 virtual ~GRTR_Strategy(); 00260 virtual bool shallForward(const dtn::data::EID& neighbor, const dtn::data::MetaBundle& bundle) const; 00261 }; 00262 00269 class GTMX_Strategy : public ForwardingStrategy 00270 { 00271 public: 00272 explicit GTMX_Strategy(unsigned int NF_max); 00273 virtual ~GTMX_Strategy(); 00274 virtual bool shallForward(const dtn::data::EID& neighbor, const dtn::data::MetaBundle& bundle) const; 00275 00276 void addForward(const dtn::data::BundleID &id); 00277 00278 private: 00279 unsigned int _NF_max; 00280 00281 typedef std::map<dtn::data::BundleID, unsigned int> nf_map; 00282 nf_map _NF_map; 00283 }; 00284 }; 00285 00286 std::ostream& operator<<(std::ostream&, const ProphetRoutingExtension::AcknowledgementSet&); 00287 00288 } // namespace routing 00289 } // namespace dtn 00290 00291 #endif // PROPHETROUTINGEXTENSION_H_