00001 // Copyright 2008 Michael Marsh, University of Maryland. 00002 // 00003 // This file is part of pydtn. 00004 // 00005 // pydtn is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // pydtn is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with pydtn. If not, see <http://www.gnu.org/licenses/>. 00017 // 00018 // The views and conclusions contained in the software and documentation 00019 // are those of the authors and should not be interpreted as representing 00020 // official policies, either expressed or implied, of the University 00021 // of Maryland. 00022 // 00023 // pydtn extends and embeds the Python interpreter, which is 00024 // Copyright 2001-2006 Python Software Foundation, All Rights Reserved, 00025 // and is released under the PSF License Agreement. 00026 // 00027 // RANLUX random number generation uses the Boost library, 00028 // Copyright 1994-2006 by various authors (details in individual files), 00029 // which is released under the Boost Software License, Version 1.0. 00030 00031 #ifndef __EPIDEMIC_EPIDEMIC_STORE_H__ 00032 #define __EPIDEMIC_EPIDEMIC_STORE_H__ 00033 00034 #include "config.h" 00035 00036 #include "simlpy/Time.h" 00037 #include "dtn/PersistentBundleStore.h" 00038 #include "dtn/ByteString.h" 00039 #include "dtn/Node.h" 00040 #include <set> 00041 #include <map> 00042 #include <list> 00043 00044 class WrapNode; 00045 00048 00050 namespace Epidemic 00051 { 00052 00054 class EpidemicBundle 00055 { 00056 public : 00058 EpidemicBundle( DTN::Bundle* b ); 00060 EpidemicBundle( const DTN::ByteString& originator, uint32_t seqNum ); 00062 EpidemicBundle( const DTN::ByteString& digest ); 00064 virtual ~EpidemicBundle(); 00065 00067 DTN::Bundle* bundle() const; 00068 00071 bool operator<( const EpidemicBundle& b ) const; 00072 00074 const Time& timeAdded() const { return m_timeAdded; } 00075 00077 const DTN::ByteString& digest() const { return m_digest; } 00078 00079 private : 00080 DTN::Bundle* m_bundle; 00081 DTN::ByteString m_originator; 00082 uint32_t m_seqNum; 00083 Time m_timeAdded; 00084 Time m_timeSent; 00085 unsigned int m_numTries; 00086 DTN::ByteString m_digest; 00087 }; 00088 00090 class EpidemicStore : public DTN::PersistentBundleStore 00091 { 00092 public : 00094 typedef std::set< EpidemicBundle > BundleList; 00096 typedef BundleList::key_type key_type; 00098 typedef BundleList::iterator iterator; 00100 typedef BundleList::const_iterator const_iterator; 00101 00103 typedef std::map< DTN::ByteString , iterator > DigestMap; 00105 typedef std::list< iterator > DestList; 00107 typedef std::map< DTN::ByteString , DestList > DestMap; 00109 typedef std::set< DTN::ByteString > HistorySet; 00111 typedef std::list< DTN::ByteString > DigestList; 00112 00116 EpidemicStore( DTN::Node* owner, uint32_t h = 0 ); 00118 virtual ~EpidemicStore(); 00119 00120 virtual void consume( DTN::Bundle* b ); 00121 00129 DTN::BundlePointer getPointer( const DTN::ByteString& digest ); 00130 00132 iterator begin(); 00137 iterator lower_bound( const key_type& x ); 00141 iterator upper_bound( const key_type& x ); 00143 iterator end(); 00144 00146 const_iterator begin() const; 00151 const_iterator lower_bound( const key_type& x ) const; 00155 const_iterator upper_bound( const key_type& x ) const; 00157 const_iterator end() const; 00158 00162 DTN::ByteString* summaryVector() const; 00163 00167 static DTN::ByteString digest( const DTN::Bundle& b ); 00168 00173 static DTN::ByteString digest( const DTN::ByteString& originator, 00174 uint32_t seqNum ); 00175 00179 static DigestList* parseSummaryVector( const DTN::ByteString& sv ); 00180 00184 void set_max_hops( uint32_t h ) { m_max_hops = h; } 00185 00189 void forwardLastHop( const DTN::ByteString& addr, DTN::Node& node ); 00190 00194 bool seen( const DTN::ByteString& digest ); 00195 00196 protected : 00201 virtual DTN::BundlePointer p_addBundle( DTN::Bundle* b ); 00204 virtual void p_deleteBundle( DTN::Bundle* b ); 00205 00214 virtual DTN::BundlePointer p_getPointer( 00215 const DTN::BundlePointer& p ); 00216 00226 virtual DTN::BundlePointer p_getPointer( 00227 const DTN::ByteString& sender, 00228 uint32_t seqNum ); 00229 00235 virtual bool p_validatePointer( const DTN::BundlePointer& p ); 00236 00240 virtual size_t p_bytesUsed() { return m_bytesUsed; } 00241 00245 virtual size_t p_bundles() { return m_list.size(); } 00246 00250 virtual void p_shrinkStore( size_t s ); 00251 00252 private : 00253 uint32_t m_max_hops; 00254 BundleList m_list; 00255 DigestMap m_digestMap; 00256 DestMap m_destMap; 00257 HistorySet m_history; 00258 size_t m_bytesUsed; 00259 }; 00260 00262 class EpidemicStoreItr : public DTN::BundlePointerRepr 00263 { 00264 public : 00268 EpidemicStoreItr( EpidemicStore& store, 00269 EpidemicStore::iterator itr ); 00271 virtual ~EpidemicStoreItr(); 00272 00277 virtual bool operator==( const DTN::BundlePointerRepr& b ); 00278 00286 virtual DTN::BundlePointerRepr* next(); 00287 00294 virtual DTN::BundlePointerRepr* clone(); 00295 00307 virtual DTN::Bundle* bundle() const; 00308 00309 private : 00310 EpidemicStore& m_store; 00311 EpidemicStore::iterator m_itr; 00312 }; 00313 } 00314 00316 00317 #endif // __EPIDEMIC_EPIDEMIC_STORE_H__
1.5.4