IBR-DTNSuite
0.8
|
00001 /* 00002 * NeighborDatabase.h 00003 * 00004 * Created on: 23.07.2010 00005 * Author: morgenro 00006 */ 00007 00008 #ifndef NEIGHBORDATABASE_H_ 00009 #define NEIGHBORDATABASE_H_ 00010 00011 #include "routing/BundleSummary.h" 00012 00013 #include <ibrdtn/data/EID.h> 00014 #include <ibrdtn/data/BundleID.h> 00015 #include <ibrcommon/data/BloomFilter.h> 00016 #include <ibrcommon/Exceptions.h> 00017 #include <ibrcommon/thread/ThreadsafeState.h> 00018 #include <map> 00019 00020 namespace dtn 00021 { 00022 namespace routing 00023 { 00029 class NeighborDatabase : public ibrcommon::Mutex 00030 { 00031 public: 00032 class BloomfilterNotAvailableException : public ibrcommon::Exception 00033 { 00034 public: 00035 BloomfilterNotAvailableException(const dtn::data::EID &host) 00036 : ibrcommon::Exception("Bloom filter is not available for this node."), eid(host) { }; 00037 00038 virtual ~BloomfilterNotAvailableException() throw () { }; 00039 00040 const dtn::data::EID eid; 00041 }; 00042 00043 class NoMoreTransfersAvailable : public ibrcommon::Exception 00044 { 00045 public: 00046 NoMoreTransfersAvailable() : ibrcommon::Exception("No more transfers allowed.") { }; 00047 virtual ~NoMoreTransfersAvailable() throw () { }; 00048 }; 00049 00050 class AlreadyInTransitException : public ibrcommon::Exception 00051 { 00052 public: 00053 AlreadyInTransitException() : ibrcommon::Exception("This bundle is already in transit.") { }; 00054 virtual ~AlreadyInTransitException() throw () { }; 00055 }; 00056 00057 class NeighborNotAvailableException : public ibrcommon::Exception 00058 { 00059 public: 00060 NeighborNotAvailableException() : ibrcommon::Exception("Entry for this neighbor not found.") { }; 00061 virtual ~NeighborNotAvailableException() throw () { }; 00062 }; 00063 00064 class NeighborEntry 00065 { 00066 public: 00067 NeighborEntry(); 00068 NeighborEntry(const dtn::data::EID &eid); 00069 virtual ~NeighborEntry(); 00070 00076 void update(const ibrcommon::BloomFilter &bf, const size_t lifetime = 0); 00077 00078 void reset(); 00079 00080 void add(const dtn::data::MetaBundle&); 00081 00082 bool has(const dtn::data::BundleID&, const bool require_bloomfilter = false) const; 00083 00088 void acquireFilterRequest() throw (NoMoreTransfersAvailable); 00089 00094 void acquireTransfer(const dtn::data::BundleID &id) throw (NoMoreTransfersAvailable, AlreadyInTransitException); 00095 00100 void releaseTransfer(const dtn::data::BundleID &id); 00101 00102 // the EID of the corresponding node 00103 const dtn::data::EID eid; 00104 00109 void expire(const size_t timestamp); 00110 00111 private: 00112 // stores bundle currently in transit 00113 ibrcommon::Mutex _transit_lock; 00114 std::set<dtn::data::BundleID> _transit_bundles; 00115 size_t _transit_max; 00116 00117 // bloomfilter used as summary vector 00118 ibrcommon::BloomFilter _filter; 00119 BundleSummary _summary; 00120 size_t _filter_expire; 00121 00122 enum FILTER_REQUEST_STATE 00123 { 00124 FILTER_AWAITING = 0, 00125 FILTER_AVAILABLE = 1, 00126 FILTER_EXPIRED = 2, 00127 FILTER_FINAL = 3 00128 }; 00129 00130 ibrcommon::ThreadsafeState<FILTER_REQUEST_STATE> _filter_state; 00131 }; 00132 00133 NeighborDatabase(); 00134 virtual ~NeighborDatabase(); 00135 00142 NeighborDatabase::NeighborEntry& get(const dtn::data::EID &eid) throw (NeighborNotAvailableException); 00143 00150 NeighborDatabase::NeighborEntry& create(const dtn::data::EID &eid); 00151 00157 NeighborDatabase::NeighborEntry& reset(const dtn::data::EID &eid); 00158 00163 void remove(const dtn::data::EID &eid); 00164 00168 void addBundle(const dtn::data::EID &neighbor, const dtn::data::MetaBundle &b); 00169 00174 void expire(const size_t timestamp); 00175 00176 private: 00177 std::map<dtn::data::EID, NeighborDatabase::NeighborEntry* > _entries; 00178 }; 00179 } 00180 } 00181 00182 #endif /* NEIGHBORDATABASE_H_ */