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 namespace dtn {
00023
00024 class BlockInfo;
00025 class BlockInfoVec;
00026 class BlockProcessor;
00027 class Bundle;
00028 class BundleTimestamp;
00029 class EndpointID;
00030 class Link;
00031
00039 class BundleProtocol {
00040 public:
00045 static void register_processor(BlockProcessor* bp);
00046
00051 static BlockProcessor* find_processor(u_int8_t type);
00052
00056 static void init_default_processors();
00057
00064 static BlockInfoVec* prepare_blocks(Bundle* bundle, Link* link);
00065
00071 static size_t generate_blocks(Bundle* bundle,
00072 BlockInfoVec* blocks,
00073 Link* link);
00074
00078 static size_t total_length(const BlockInfoVec* blocks);
00079
00084 static size_t payload_offset(const BlockInfoVec* blocks);
00085
00093 static size_t produce(const Bundle* bundle, const BlockInfoVec* blocks,
00094 u_char* data, size_t offset, size_t len, bool* last);
00095
00109 static int consume(Bundle* bundle, u_char* data, size_t len, bool* last);
00110
00114 typedef enum {
00115 REASON_NO_ADDTL_INFO = 0x00,
00116 REASON_LIFETIME_EXPIRED = 0x01,
00117 REASON_FORWARDED_UNIDIR_LINK = 0x02,
00118 REASON_TRANSMISSION_CANCELLED = 0x03,
00119 REASON_DEPLETED_STORAGE = 0x04,
00120 REASON_ENDPOINT_ID_UNINTELLIGIBLE = 0x05,
00121 REASON_NO_ROUTE_TO_DEST = 0x06,
00122 REASON_NO_TIMELY_CONTACT = 0x07,
00123 REASON_BLOCK_UNINTELLIGIBLE = 0x08,
00124 } status_report_reason_t;
00125
00133 static bool validate(Bundle* bundle,
00134 status_report_reason_t* reception_reason,
00135 status_report_reason_t* deletion_reason);
00136
00141 static void set_timestamp(u_char* bp, const BundleTimestamp* tv);
00142
00149 static void set_timestamp(u_int64_t* bp, const BundleTimestamp* tv) {
00150 set_timestamp((u_char *) bp, tv);
00151 }
00152
00158 static void get_timestamp(BundleTimestamp* tv, const u_char* bp);
00159
00165 static void get_timestamp(BundleTimestamp* tv, const u_int64_t* bp) {
00166 get_timestamp(tv, (u_char *) bp);
00167 }
00168
00172 static const int CURRENT_VERSION = 0x04;
00173
00177 typedef enum {
00178 PRIMARY_BLOCK = 0x000,
00179 PAYLOAD_BLOCK = 0x001,
00180 PREVIOUS_HOP_BLOCK = 0x005,
00181 API_EXTENSION_BLOCK = 0x100,
00182 } bundle_block_type_t;
00183
00188 typedef enum {
00189 BLOCK_FLAG_REPLICATE = 1 << 0,
00190 BLOCK_FLAG_REPORT_ONERROR = 1 << 1,
00191 BLOCK_FLAG_DISCARD_BUNDLE_ONERROR = 1 << 2,
00192 BLOCK_FLAG_LAST_BLOCK = 1 << 3,
00193 BLOCK_FLAG_DISCARD_BLOCK_ONERROR = 1 << 4,
00194 BLOCK_FLAG_FORWARDED_UNPROCESSED = 1 << 5
00195 } block_flag_t;
00196
00201 struct BlockPreamble {
00202 u_int8_t type;
00203 u_int8_t flags;
00204 u_char length[0];
00205 } __attribute__((packed));
00206
00210 typedef enum {
00211 ADMIN_STATUS_REPORT = 0x01,
00212 ADMIN_CUSTODY_SIGNAL = 0x02,
00213 ADMIN_ANNOUNCE = 0x05,
00214 } admin_record_type_t;
00215
00219 typedef enum {
00220 ADMIN_IS_FRAGMENT = 0x01,
00221 } admin_record_flags_t;
00222
00226 typedef enum {
00227 STATUS_RECEIVED = 0x01,
00228 STATUS_CUSTODY_ACCEPTED = 0x02,
00229 STATUS_FORWARDED = 0x04,
00230 STATUS_DELIVERED = 0x08,
00231 STATUS_DELETED = 0x10,
00232 STATUS_ACKED_BY_APP = 0x20,
00233 STATUS_UNUSED = 0x40,
00234 STATUS_UNUSED2 = 0x80,
00235 } status_report_flag_t;
00236
00240 typedef enum {
00241 CUSTODY_NO_ADDTL_INFO = 0x00,
00242 CUSTODY_REDUNDANT_RECEPTION = 0x03,
00243 CUSTODY_DEPLETED_STORAGE = 0x04,
00244 CUSTODY_ENDPOINT_ID_UNINTELLIGIBLE = 0x05,
00245 CUSTODY_NO_ROUTE_TO_DEST = 0x06,
00246 CUSTODY_NO_TIMELY_CONTACT = 0x07,
00247 CUSTODY_BLOCK_UNINTELLIGIBLE = 0x08
00248 } custody_signal_reason_t;
00249
00256 static bool get_admin_type(const Bundle* bundle,
00257 admin_record_type_t* type);
00258
00259 private:
00264 static BlockProcessor* processors_[256];
00265
00266 };
00267
00268 }
00269
00270 #endif