Bundle.cc

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 #include "Bundle.h"
00032 #include <netinet/in.h>
00033 
00034 using namespace DTN;
00035 
00036 Bundle::Bundle( uint32_t seq,
00037                 const ByteString& src,
00038                 const struct timeval& creat,
00039                 const struct timeval& expir,
00040                 BundleType t,
00041                 const ByteString& app ) :
00042    m_seqNum( htonl(seq) ),
00043    m_source( src ),
00044    m_custodian( src ),
00045    m_send( src ),
00046    m_recv( src ),
00047    m_type( t ),
00048    m_app( app ),
00049    m_hopCount( 0 )
00050 {
00051    m_created.tv_sec = creat.tv_sec;
00052    m_created.tv_usec = creat.tv_usec;
00053    m_expiry.tv_sec = expir.tv_sec;
00054    m_expiry.tv_usec = expir.tv_usec;
00055 }
00056 
00057 Bundle::Bundle( const Bundle& aOther ):
00058    m_seqNum( aOther.m_seqNum ),
00059    m_source( aOther.m_source ),
00060    m_destination( aOther.m_destination ),
00061    m_custodian( aOther.m_custodian ),
00062    m_send( aOther.m_send ),
00063    m_recv( aOther.m_recv ),
00064    m_payload( aOther.m_payload ),
00065    m_type ( aOther.m_type ),
00066    m_app ( aOther.m_app ),
00067    m_hopCount( aOther.m_hopCount )
00068 {
00069    m_created.tv_sec = aOther.m_created.tv_sec;
00070    m_created.tv_usec = aOther.m_created.tv_usec;
00071    m_expiry.tv_sec = aOther.m_expiry.tv_sec;
00072    m_expiry.tv_usec = aOther.m_expiry.tv_usec;
00073 }
00074 
00075 Bundle::Bundle( uint32_t seq,
00076                 const ByteString& src,
00077                 const ByteString& dest,
00078                 const struct timeval& creat,
00079                 const struct timeval& expir,
00080                 BundleType t,
00081                 const ByteString& app ) :
00082    m_seqNum( htonl(seq) ),
00083    m_source( src ),
00084    m_destination( dest ),
00085    m_custodian( src ),
00086    m_send( src ),
00087    m_recv( src ),
00088    m_type( t ),
00089    m_app( app ),
00090    m_hopCount( 0 )
00091 {
00092    m_created.tv_sec = creat.tv_sec;
00093    m_created.tv_usec = creat.tv_usec;
00094    m_expiry.tv_sec = expir.tv_sec;
00095    m_expiry.tv_usec = expir.tv_usec;
00096 }
00097 
00098 Bundle::Bundle( uint32_t seq,
00099                 const ByteString& src,
00100                 const ByteString& dest,
00101                 const ByteString& data,
00102                 const struct timeval& creat,
00103                 const struct timeval& expir,
00104                 BundleType t,
00105                 const ByteString& app ) :
00106    m_seqNum( htonl(seq) ),
00107    m_source( src ),
00108    m_destination( dest ),
00109    m_custodian( src ),
00110    m_send( src ),
00111    m_recv( src ),
00112    m_payload( data ),
00113    m_type( t ),
00114    m_app( app ),
00115    m_hopCount( 0 )
00116 {
00117    m_created.tv_sec = creat.tv_sec;
00118    m_created.tv_usec = creat.tv_usec;
00119    m_expiry.tv_sec = expir.tv_sec;
00120    m_expiry.tv_usec = expir.tv_usec;
00121 }
00122 
00123 Bundle::~Bundle()
00124 {
00125 }
00126 
00127 Bundle*
00128 Bundle::clone() const
00129 {
00130    return new Bundle(*this);
00131 }
00132 
00133 bool
00134 Bundle::expired() const
00135 {
00136    const struct timeval tv = dtn_time();
00137 
00138    return
00139       ( tv.tv_sec > m_expiry.tv_sec ) ||
00140       ( ( tv.tv_sec == m_expiry.tv_sec ) &&
00141         ( tv.tv_usec > m_expiry.tv_usec ) );
00142 }

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