00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef __DTN_NODE_H__
00032 #define __DTN_NODE_H__
00033
00034 #include "config.h"
00035 #include "Bundle.h"
00036 #include "Consumer.h"
00037 #include "VolatileBundleStore.h"
00038 #include "PersistentBundleStore.h"
00039 #include "VolatileStorePolicy.h"
00040 #include "ForwardingPolicy.h"
00041 #include "CustodyPolicy.h"
00042
00043 #include <map>
00044 #include <set>
00045
00046 namespace DTN
00047 {
00048 class Link;
00049
00067 class Node
00068 {
00069 public:
00071 typedef std::set< Link* > LinkList;
00072
00074 Node();
00075
00077 virtual ~Node();
00078
00080 uint32_t nextSeq() { return m_seqNum++; }
00081
00086 void forward( Bundle* b );
00087
00090 void broadcast( Bundle* b );
00091
00095 bool addPersistent( const Bundle& b );
00096
00100 bool validate( const BundlePointer& p );
00101
00105 bool validatePersistent( const BundlePointer& p );
00106
00111 void remove( Bundle* b,
00112 bool dealloc = true,
00113 const DropCause& c=DropCause::inst );
00114
00119 void removePersistent( Bundle* b, bool dropping = true );
00120
00125 void send( Bundle* b, Link& l );
00126
00132 void recv( Bundle* b );
00133
00138 void forwardOn( Link& l );
00139
00141 void retryStored();
00142
00147 void drop( Bundle* b, const DropCause& c=DropCause::inst );
00148
00157 void recordPersistentRemove( const Bundle& b, bool cleanup=true );
00158
00172 virtual void setAddr( const ByteString& addr );
00173
00175 const ByteString& addr() const { return m_addr; }
00176
00180 void setConsumer( Consumer* c );
00181
00183 size_t volatileCap() const { return m_volatileCap; }
00184
00187 size_t usedVolatileCap( bool cleanup=true ) const;
00188
00190 size_t volatileBundles( bool cleanup=true ) const;
00191
00193 size_t persistentCap() const { return m_persistentCap; }
00194
00197 size_t usedPersistentCap( bool cleanup=true ) const;
00198
00200 size_t persistentBundles( bool cleanup=true ) const;
00201
00205 BundlePointer cachedVolatile();
00206
00210 BundlePointer cachedVolatile( const BundlePointer& p );
00211
00216 BundlePointer cachedVolatile( const ByteString& sender,
00217 uint32_t seqNum );
00218
00222 const BundlePointer cachedVolatile() const;
00223
00227 const BundlePointer cachedVolatile( const BundlePointer& p ) const;
00228
00233 const BundlePointer cachedVolatile( const ByteString& sender,
00234 uint32_t seqNum ) const;
00235
00239 BundlePointer cachedPersistent();
00240
00244 BundlePointer cachedPersistent( const BundlePointer& p );
00245
00250 BundlePointer cachedPersistent( const ByteString& sender,
00251 uint32_t seqNum );
00252
00256 const BundlePointer cachedPersistent() const;
00257
00261 const BundlePointer cachedPersistent( const BundlePointer& p ) const;
00262
00267 const BundlePointer cachedPersistent( const ByteString& sender,
00268 uint32_t seqNum ) const;
00269
00275 void setVolatileStore( VolatileBundleStore* s );
00276
00282 void setPersistentStore( PersistentBundleStore* s );
00283
00291 void setVolatileStorePolicy( VolatileStorePolicy* p );
00292
00300 void setForwardingPolicy( ForwardingPolicy* p );
00301
00309 void setCustodyPolicy( CustodyPolicy* p );
00310
00312 bool hasVolatileStore() const { return 0 != m_volatileStore; }
00314 bool hasPersistentStore() const { return 0 != m_persistentStore; }
00316 bool hasVolatileStorePolicy() const { return 0 != m_vstorePol; }
00318 bool hasForwardingPolicy() const { return 0 != m_forwPol; }
00320 bool hasCustodyPolicy() const { return 0 != m_custPol; }
00321
00324 void setVolatileCap( size_t cap );
00325
00328 void setPersistentCap( size_t cap );
00329
00333 void signalExhausted( const Bundle& b );
00334
00339 void addLink( Link* l );
00340
00341 protected:
00350 virtual bool ours( const ByteString& destination );
00351
00359 virtual void consume( Bundle* b );
00360
00363 virtual void acknowledge( const Bundle& b );
00364
00365 private:
00366 uint32_t m_seqNum;
00367 ByteString m_addr;
00368 Consumer* m_consumer;
00369 size_t m_volatileCap;
00370 BundleStore* m_volatileStore;
00371 size_t m_persistentCap;
00372 BundleStore* m_persistentStore;
00373 VolatileStorePolicy* m_vstorePol;
00374 ForwardingPolicy* m_forwPol;
00375 CustodyPolicy* m_custPol;
00376 LinkList m_links;
00377 };
00378
00379 };
00380
00381 #endif