Bundle.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_BUNDLE_H__
00032 #define __DTN_BUNDLE_H__
00033 
00034 #include "config.h"
00035 #include "ByteString.h"
00036 #include <sys/time.h>
00037 
00038 namespace DTN
00039 {
00040 
00042 struct timeval dtn_time();
00043    
00059 class Bundle
00060 {
00061    public :
00063       typedef unsigned char  BundleType;
00064 
00066       enum
00067       {
00068          kData      = 1 << 0, 
00069          kACK       = 1 << 1, 
00070          kNoACK     = 1 << 2, 
00071          kCustodial = 1 << 3, 
00072          kBcast     = 1 << 4, 
00073       };
00074 
00082       Bundle( uint32_t seq,
00083               const ByteString& src,
00084               const struct timeval& creat,
00085               const struct timeval& expir,
00086               BundleType t = kData,
00087               const ByteString& app = ByteString() );
00088 
00091       Bundle( const Bundle& aOther );
00092 
00101       Bundle( uint32_t seq,
00102               const ByteString& src,
00103               const ByteString& dest,
00104               const struct timeval& creat,
00105               const struct timeval& expir,
00106               BundleType t = kData,
00107               const ByteString& app = ByteString() );
00108 
00118       Bundle( uint32_t seq,
00119               const ByteString& src,
00120               const ByteString& dest,
00121               const ByteString& data,
00122               const struct timeval& creat,
00123               const struct timeval& expir,
00124               BundleType t = kData,
00125               const ByteString& app = ByteString() );
00126 
00128       virtual ~Bundle();
00129 
00131       virtual Bundle* clone() const;
00132 
00134       virtual unsigned int size() const { return
00135                                              4 + // seqNum
00136                                              m_source.length() +
00137                                              m_destination.length() +
00138                                              m_custodian.length() +
00139                                              m_send.length() +
00140                                              m_recv.length() +
00141                                              m_payload.length() +
00142                                              8 + // created
00143                                              8 + // TTL
00144                                              1 + // type
00145                                              m_app.length() +
00146                                              4; } // hop count
00147 
00149       uint32_t seqNum()              const { return m_seqNum; }
00151       const ByteString& source()      const { return m_source; }
00153       const ByteString& destination() const { return m_destination; }
00155       const ByteString& custodian()   const { return m_custodian; }
00157       const ByteString& send()        const { return m_send; }
00159       const ByteString& recv()        const { return m_recv; }
00161       const ByteString& payload()     const { return m_payload; }
00163       const struct timeval& created() const { return m_created; }
00165       const struct timeval& expiry()  const { return m_expiry; }
00167       BundleType type()               const { return m_type; }
00169       const ByteString& app()         const { return m_app; }
00171       uint32_t hopCount()            const { return m_hopCount; }
00172 
00174       ByteString& destination() { return m_destination; }
00176       ByteString& custodian()   { return m_custodian; }
00178       ByteString& send()        { return m_send; }
00180       ByteString& recv()        { return m_recv; }
00182       ByteString& payload()     { return m_payload; }
00184       struct timeval& created() { return m_created;}
00186       struct timeval& expiry() { return m_expiry;}
00188       BundleType& type()        { return m_type; }
00189 
00191       virtual bool expired() const;
00192 
00194       void incrHop() { ++m_hopCount; }
00195 
00196    private :
00198       Bundle();
00199 
00200       uint32_t       m_seqNum; 
00201       ByteString      m_source; 
00202       ByteString      m_destination; 
00203       ByteString      m_custodian; 
00204       ByteString      m_send; 
00205       ByteString      m_recv; 
00206       ByteString      m_payload; 
00207       struct timeval  m_created; 
00208       struct timeval  m_expiry; 
00209       BundleType      m_type; 
00210       ByteString      m_app; 
00211       uint32_t       m_hopCount; 
00212 };
00213 
00214 }; // DTN
00215 
00216 #endif /* __DTN_BUNDLE_H__ */

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