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 #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 +
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 +
00143 8 +
00144 1 +
00145 m_app.length() +
00146 4; }
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 };
00215
00216 #endif