Header.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_HEADER_H__
00032 #define __DTN_HEADER_H__
00033 
00034 #include "config.h"
00035 #include "ByteString.h"
00036 
00037 namespace DTN
00038 {
00039 
00051 class SDNV
00052 {
00053    public :
00055       SDNV() {}
00057       SDNV( uint64_t l ) { assign(l); }
00059       SDNV( const ByteString& s );
00061       SDNV( const SDNV& v ) : m_val( v.val() ) {}
00063       ~SDNV() {}
00064 
00066       SDNV& operator=( uint64_t l ) { assign(l); return *this; }
00068       SDNV& operator=( const SDNV& v );
00069 
00071       operator uint64_t() const;
00072 
00074       const ByteString& val() const { return m_val; }
00075 
00076    private :
00077       void assign( uint64_t l );
00078 
00079       ByteString  m_val;
00080 };
00081 
00082 
00089 class Header
00090 {
00091    public :
00093       Header();
00095       Header( const ByteString& hdr );
00097       Header( const Header& hdr );
00099       virtual ~Header();
00100 
00102       const ByteString& data() const { return m_data; }
00103 
00104    protected :
00105       ByteString  m_data; 
00106 };
00107 
00108 
00125 class PrimaryHeader : public Header
00126 {
00127    public :
00129       enum PrimaryBundleFlags
00130       {
00132          kBundleFlagFragment = ( 1U << 0 ),
00134          kBundleFlagAdmin    = ( 1U << 1 ),
00136          kBundleFlagNF       = ( 1U << 2 ),
00138          kBundleFlagCTR      = ( 1U << 3 ),
00140          kBundleFlagDEPS     = ( 1U << 4 ),
00142          kBundleFlagRsrv3    = ( 1U << 5 ),
00144          kBundleFlagRsrv2    = ( 1U << 6 ),
00146          kBundleFlagRsrv1    = ( 1U << 7 )
00147       };
00148 
00150       enum SRRFlags
00151       {
00153          kSRR_none = 0x00,
00155          kSRR_reception = 0x01,
00157          kSRR_custody = 0x02,
00159          kSRR_forward = 0x04,
00161          kSRR_deliver = 0x08,
00163          kSRR_delete = 0x10,
00165          kSRR_ack = 0x20,
00167          kSRR_rsrv2 = 0x40,
00169          kSRR_rsrv1 = 0x80
00170       };
00171 
00173       PrimaryHeader();
00176       PrimaryHeader( const ByteString& hdr );
00178       PrimaryHeader( const PrimaryHeader& hdr );
00180       virtual ~PrimaryHeader();
00181 
00183       unsigned char version() const;
00185       unsigned char flags() const;
00187       unsigned char COS() const;
00189       unsigned char SRR() const;
00191       const SDNV& length() const;
00193       uint16_t destinationSchemeOffset() const;
00195       uint16_t destinationSSPOffset() const;
00197       uint16_t sourceSchemeOffset() const;
00199       uint16_t sourceSSPOffset() const;
00201       uint16_t reportToSchemeOffset() const;
00203       uint16_t reportToSSPOffset() const;
00205       uint16_t custodianSchemeOffset() const;
00207       uint16_t custodianSSPOffset() const;
00209       uint32_t creationTime() const;
00211       uint32_t creationSeqNum() const;
00213       uint32_t lifetime() const;
00215       const SDNV& dictionaryLength() const;
00217       const ByteString& dictionary() const;
00219       const SDNV& fragmentOffset() const;
00221       const SDNV& applicationDataUnitLength() const;
00222 
00223    private :
00228       uint16_t stringToShort( ByteString::size_type offset ) const;
00233       uint32_t  stringToInt( ByteString::size_type offset ) const;
00235       void parse() const;
00236 
00237       mutable bool  m_parsed;
00238 
00239       mutable SDNV       m_length;
00240       mutable uint16_t   m_destinationSchemeOffset;
00241       mutable uint16_t   m_destinationSSPOffset;
00242       mutable uint16_t   m_sourceSchemeOffset;
00243       mutable uint16_t   m_sourceSSPOffset;
00244       mutable uint16_t   m_reportToSchemeOffset;
00245       mutable uint16_t   m_reportToSSPOffset;
00246       mutable uint16_t   m_custodianSchemeOffset;
00247       mutable uint16_t   m_custodianSSPOffset;
00248       mutable uint32_t   m_creationTime;
00249       mutable uint32_t   m_creationSeqNum;
00250       mutable uint32_t   m_lifetime;
00251       mutable SDNV       m_dictionaryLength;
00252       mutable ByteString m_dictionary;
00253       mutable SDNV       m_fragmentOffset;
00254       mutable SDNV       m_applicationDataUnitLength;
00255 };
00256 
00257 
00272 class RegularHeader : public Header
00273 {
00274    public :
00276       enum Types
00277       {
00278          kUnknownHeader = 0U, 
00279          kPayloadHeader = 1U  
00280       };
00281 
00283       enum BundleHeaderFlags
00284       {
00286          kHeaderFlagRepl    = ( 1U << 0 ),
00288          kHeaderFlagStatus  = ( 1U << 1 ),
00290          kHeaderFlagDiscard = ( 1U << 2 ),
00292          kHeaderFlagLast    = ( 1U << 3 ),
00294          kHeaderFlagRsrv4   = ( 1U << 4 ),
00296          kHeaderFlagRsrv3   = ( 1U << 5 ),
00298          kHeaderFlagRsrv2   = ( 1U << 6 ),
00300          kHeaderFlagRsrv1   = ( 1U << 7 )
00301       };
00302 
00304       RegularHeader();
00307       RegularHeader( const ByteString& hdr );
00309       RegularHeader( const RegularHeader& hdr );
00311       virtual ~RegularHeader();
00312 
00315       unsigned char typeCode() const;
00322       unsigned char flags() const;
00324       SDNV length() const;
00325 };
00326 
00327 
00335 class PayloadHeader : public RegularHeader
00336 {
00337    public :
00339       PayloadHeader();
00351       PayloadHeader( const ByteString& pld, unsigned char flags=0 );
00353       PayloadHeader( const PayloadHeader& hdr );
00355       virtual ~PayloadHeader();
00356 
00364       ByteString::size_type offset() const { return m_offset; }
00373       ByteString payload() const;
00374 
00375    private :
00376       ByteString::size_type  m_offset;
00377 };
00378 
00379 }; // DTN
00380 
00381 #endif /* __DTN_HEADER_H__ */

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