Node.h

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 __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 }; // DTN
00380 
00381 #endif /* __DTN_NODE_H__ */

Generated on Mon Mar 24 11:15:45 2008 for Pydtn Simulator by  doxygen 1.5.4