00001 #ifndef BUNDLE_H_
00002 #define BUNDLE_H_
00003
00004 #include <sys/types.h>
00005 #include "Block.h"
00006 #include "Exceptions.h"
00007 #include "Dictionary.h"
00008 #include "NetworkFrame.h"
00009 #include "PrimaryFlags.h"
00010 #include "AdministrativeBlock.h"
00011 #include <list>
00012
00013 using namespace dtn::exceptions;
00014 using namespace std;
00015
00016 namespace dtn
00017 {
00018 namespace data
00019 {
00023 enum BUNDLE_FIELDS
00024 {
00025 VERSION = 0,
00026 PROCFLAGS = 1,
00027 BLOCKLENGTH = 2,
00028 DESTINATION_SCHEME = 3,
00029 DESTINATION_SSP = 4,
00030 SOURCE_SCHEME = 5,
00031 SOURCE_SSP = 6,
00032 REPORTTO_SCHEME = 7,
00033 REPORTTO_SSP = 8,
00034 CUSTODIAN_SCHEME = 9,
00035 CUSTODIAN_SSP = 10,
00036 CREATION_TIMESTAMP = 11,
00037 CREATION_TIMESTAMP_SEQUENCE = 12,
00038 LIFETIME = 13,
00039 DICTIONARY_LENGTH = 14,
00040 DICTIONARY_BYTEARRAY = 15,
00041 FRAGMENTATION_OFFSET = 16,
00042 APPLICATION_DATA_LENGTH = 17
00043 };
00044
00048 static const unsigned char BUNDLE_VERSION = 0x06;
00049
00053 class Bundle
00054 {
00055 public:
00060 Bundle(NetworkFrame *frame);
00061
00067 Bundle(NetworkFrame *frame, const list<Block*> blocks);
00068
00069 Bundle(const Bundle &b);
00070
00074 virtual ~Bundle();
00075
00083 bool operator==(const Bundle& other) const;
00084
00091 bool operator!=(const Bundle& other) const;
00092
00100 void setFragment(bool value);
00101
00108 unsigned char* getData() const;
00109
00115 unsigned int getLength() const;
00116
00129 u_int64_t getInteger(const BUNDLE_FIELDS field) const throw (InvalidFieldException, FieldDoesNotExist);
00130
00136 void setInteger(const BUNDLE_FIELDS field, const u_int64_t value) throw (InvalidFieldException, FieldDoesNotExist);
00137
00142 string getDestination() const;
00143
00148 void setDestination(string destination);
00149
00154 string getSource() const;
00155
00160 void setSource(string source);
00161
00166 string getReportTo() const;
00167
00172 void setReportTo(string reportto);
00173
00178 string getCustodian() const;
00179
00184 void setCustodian(string custodian);
00185
00192 PrimaryFlags getPrimaryFlags() const;
00193
00198 void setPrimaryFlags(PrimaryFlags &flags);
00199
00204 const list<Block*> &getBlocks() const;
00205
00210 void appendBlock(Block *block);
00211
00216 void insertBlock(Block *block);
00217
00222 void removeBlock(Block *block);
00223
00228 const NetworkFrame &getFrame() const;
00229
00233 void updateBlockLength();
00234
00239 bool isExpired() const;
00240
00245 string toString() const;
00246
00251 PayloadBlock* getPayloadBlock() const;
00252
00257 list<Block*> getBlocks(const unsigned char type) const;
00258
00259 #ifdef DO_DEBUG_OUTPUT
00260 void debug() const;
00261 #endif
00262
00263 private:
00275 int getPosition(BUNDLE_FIELDS field) throw (FieldDoesNotExist, InvalidBundleData);
00276
00277 NetworkFrame *m_frame;
00278
00279 Dictionary getDictionary() const;
00280 void commitDictionary(const Dictionary &dict);
00281
00282 list<Block*> m_blocks;
00283 };
00284 }
00285 }
00286
00287 #endif