PrimaryBlockProcessor.h

Go to the documentation of this file.
00001 /*
00002  *    Copyright 2006 Intel Corporation
00003  * 
00004  *    Licensed under the Apache License, Version 2.0 (the "License");
00005  *    you may not use this file except in compliance with the License.
00006  *    You may obtain a copy of the License at
00007  * 
00008  *        http://www.apache.org/licenses/LICENSE-2.0
00009  * 
00010  *    Unless required by applicable law or agreed to in writing, software
00011  *    distributed under the License is distributed on an "AS IS" BASIS,
00012  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  *    See the License for the specific language governing permissions and
00014  *    limitations under the License.
00015  */
00016 
00017 #ifndef _PRIMARY_BLOCK_PROCESSOR_H_
00018 #define _PRIMARY_BLOCK_PROCESSOR_H_
00019 
00020 #include "BlockProcessor.h"
00021 
00022 namespace dtn {
00023 
00024 class DictionaryVector;
00025 class EndpointID;
00026 
00030 class PrimaryBlockProcessor : public BlockProcessor {
00031 public:
00033     PrimaryBlockProcessor();
00034     
00036     int consume(Bundle* bundle, BlockInfo* block, u_char* buf, size_t len);
00037     void generate(const Bundle* bundle, Link* link,
00038                   BlockInfo* block, bool last);
00040 
00041 protected:
00046     typedef enum {
00047         BUNDLE_IS_FRAGMENT             = 1 << 0,
00048         BUNDLE_IS_ADMIN                = 1 << 1,
00049         BUNDLE_DO_NOT_FRAGMENT         = 1 << 2,
00050         BUNDLE_CUSTODY_XFER_REQUESTED  = 1 << 3,
00051         BUNDLE_SINGLETON_DESTINATION   = 1 << 4
00052     } bundle_processing_flag_t;
00053     
00058     struct PrimaryBlock1 {
00059         u_int8_t version;
00060         u_int8_t bundle_processing_flags;
00061         u_int8_t class_of_service_flags;
00062         u_int8_t status_report_request_flags;
00063         u_char   block_length[0]; // SDNV
00064     } __attribute__((packed));
00065 
00070     struct PrimaryBlock2 {
00071         u_int16_t dest_scheme_offset;
00072         u_int16_t dest_ssp_offset;
00073         u_int16_t source_scheme_offset;
00074         u_int16_t source_ssp_offset;
00075         u_int16_t replyto_scheme_offset;
00076         u_int16_t replyto_ssp_offset;
00077         u_int16_t custodian_scheme_offset;
00078         u_int16_t custodian_ssp_offset;
00079         u_int64_t creation_ts;
00080         u_int32_t lifetime;
00081 
00082     } __attribute__((packed));
00083 
00084 
00087     friend class BundleProtocol;
00088     
00089     static size_t get_primary_len(const Bundle* bundle,
00090                                   DictionaryVector* dict,
00091                                   size_t* dictionary_len,
00092                                   size_t* primary_var_len);
00093 
00094     static size_t get_primary_len(const Bundle* bundle);
00095 
00096     static void add_to_dictionary(const EndpointID& eid,
00097                                   DictionaryVector* dict,
00098                                   size_t* dictlen);
00099     
00100     static void get_dictionary_offsets(DictionaryVector *dict,
00101                                        const EndpointID& eid,
00102                                        u_int16_t* scheme_offset,
00103                                        u_int16_t* ssp_offset);
00104     
00105 
00106     static bool extract_dictionary_eid(EndpointID* eid, const char* what,
00107                                        u_int16_t* scheme_offsetp,
00108                                        u_int16_t* ssp_offsetp,
00109                                        u_char* dictionary,
00110                                        u_int32_t dictionary_len);
00111 
00112     static void debug_dump_dictionary(const char* bp, size_t len,
00113                                       PrimaryBlock2* primary2);
00114     
00115     static u_int8_t format_bundle_flags(const Bundle* bundle);
00116     static void parse_bundle_flags(Bundle* bundle, u_int8_t flags);
00117 
00118     static u_int8_t format_cos_flags(const Bundle* bundle);
00119     static void parse_cos_flags(Bundle* bundle, u_int8_t cos_flags);
00120 
00121     static u_int8_t format_srr_flags(const Bundle* bundle);
00122     static void parse_srr_flags(Bundle* bundle, u_int8_t srr_flags);
00124 };
00125 
00126 } // namespace dtn
00127 
00128 #endif /* _PRIMARY_BLOCK_PROCESSOR_H_ */

Generated on Sat Sep 8 08:36:17 2007 for DTN Reference Implementation by  doxygen 1.5.3