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 #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 }