00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _BUNDLE_PROTOCOL_H_
00018 #define _BUNDLE_PROTOCOL_H_
00019
00020 #include <sys/types.h>
00021
00022 #include "contacts/Link.h"
00023
00024 namespace dtn {
00025
00026 class BlockInfo;
00027 class BlockInfoVec;
00028 class BlockProcessor;
00029 class Bundle;
00030 class BundleTimestamp;
00031 class EndpointID;
00032
00040 class BundleProtocol {
00041 public:
00046 static void register_processor(BlockProcessor* bp);
00047
00052 static BlockProcessor* find_processor(u_int8_t type);
00053
00057 static void init_default_processors();
00058
00063 static void reload_post_process(Bundle* bundle);
00064
00071 static BlockInfoVec* prepare_blocks(Bundle* bundle, const LinkRef& link);
00072
00078 static size_t generate_blocks(Bundle* bundle,
00079 BlockInfoVec* blocks,
00080 const LinkRef& link);
00081
00082 static void delete_blocks(Bundle* bundle, const LinkRef& link);
00083
00087 static size_t total_length(const BlockInfoVec* blocks);
00088
00093 static size_t payload_offset(const BlockInfoVec* blocks);
00094
00102 static size_t produce(const Bundle* bundle, const BlockInfoVec* blocks,
00103 u_char* data, size_t offset, size_t len, bool* last);
00104
00118 static int consume(Bundle* bundle, u_char* data, size_t len, bool* last);
00119
00123 typedef enum {
00124 REASON_NO_ADDTL_INFO = 0x00,
00125 REASON_LIFETIME_EXPIRED = 0x01,
00126 REASON_FORWARDED_UNIDIR_LINK = 0x02,
00127 REASON_TRANSMISSION_CANCELLED = 0x03,
00128 REASON_DEPLETED_STORAGE = 0x04,
00129 REASON_ENDPOINT_ID_UNINTELLIGIBLE = 0x05,
00130 REASON_NO_ROUTE_TO_DEST = 0x06,
00131 REASON_NO_TIMELY_CONTACT = 0x07,
00132 REASON_BLOCK_UNINTELLIGIBLE = 0x08,
00133 REASON_SECURITY_FAILED = 0x09,
00134 } status_report_reason_t;
00135
00143 static bool validate(Bundle* bundle,
00144 status_report_reason_t* reception_reason,
00145 status_report_reason_t* deletion_reason);
00146
00151 static int set_timestamp(u_char* bp, size_t len, const BundleTimestamp& tv);
00152
00158 static int get_timestamp(BundleTimestamp* tv, const u_char* bp, size_t len);
00159
00163 static size_t ts_encoding_len(const BundleTimestamp& tv);
00164
00168 static const int CURRENT_VERSION = 0x06;
00169
00170 static const unsigned PREAMBLE_FIXED_LENGTH = 1;
00171
00176 typedef enum {
00177 PRIMARY_BLOCK = 0x000,
00178 PAYLOAD_BLOCK = 0x001,
00179 BUNDLE_AUTHENTICATION_BLOCK = 0x002,
00180 PAYLOAD_SECURITY_BLOCK = 0x003,
00181 CONFIDENTIALITY_BLOCK = 0x004,
00182 PREVIOUS_HOP_BLOCK = 0x005,
00183 METADATA_BLOCK = 0x008,
00184 SESSION_BLOCK = 0x009,
00185 SEQUENCE_ID_BLOCK = 0x010,
00186 OBSOLETES_ID_BLOCK = 0x011,
00187 API_EXTENSION_BLOCK = 0x100,
00188 UNKNOWN_BLOCK = 0x101,
00189 } bundle_block_type_t;
00190
00195 typedef enum {
00196 BLOCK_FLAG_REPLICATE = 1 << 0,
00197 BLOCK_FLAG_REPORT_ONERROR = 1 << 1,
00198 BLOCK_FLAG_DISCARD_BUNDLE_ONERROR = 1 << 2,
00199 BLOCK_FLAG_LAST_BLOCK = 1 << 3,
00200 BLOCK_FLAG_DISCARD_BLOCK_ONERROR = 1 << 4,
00201 BLOCK_FLAG_FORWARDED_UNPROCESSED = 1 << 5,
00202 BLOCK_FLAG_EID_REFS = 1 << 6
00203 } block_flag_t;
00204
00209 struct BlockPreamble {
00210 u_int8_t type;
00211 u_int8_t flags;
00212 u_char length[0];
00213 } __attribute__((packed));
00214
00218 typedef enum {
00219 ADMIN_STATUS_REPORT = 0x01,
00220 ADMIN_CUSTODY_SIGNAL = 0x02,
00221 ADMIN_ANNOUNCE = 0x05,
00222 } admin_record_type_t;
00223
00227 typedef enum {
00228 ADMIN_IS_FRAGMENT = 0x01,
00229 } admin_record_flags_t;
00230
00234 typedef enum {
00235 STATUS_RECEIVED = 1 << 14,
00236 STATUS_CUSTODY_ACCEPTED = 1 << 15,
00237 STATUS_FORWARDED = 1 << 16,
00238 STATUS_DELIVERED = 1 << 17,
00239 STATUS_DELETED = 1 << 18,
00240 STATUS_ACKED_BY_APP = 1 << 19,
00241 STATUS_UNUSED2 = 1 << 20,
00242 } status_report_flag_t;
00243
00247 typedef enum {
00248 CUSTODY_NO_ADDTL_INFO = 0x00,
00249 CUSTODY_REDUNDANT_RECEPTION = 0x03,
00250 CUSTODY_DEPLETED_STORAGE = 0x04,
00251 CUSTODY_ENDPOINT_ID_UNINTELLIGIBLE = 0x05,
00252 CUSTODY_NO_ROUTE_TO_DEST = 0x06,
00253 CUSTODY_NO_TIMELY_CONTACT = 0x07,
00254 CUSTODY_BLOCK_UNINTELLIGIBLE = 0x08
00255 } custody_signal_reason_t;
00256
00263 static bool get_admin_type(const Bundle* bundle,
00264 admin_record_type_t* type);
00265
00266 private:
00271 static BlockProcessor* processors_[256];
00272
00273 };
00274
00275 }
00276
00277 #endif