00001 /* 00002 * Copyright 2004-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 _BUNDLE_H_ 00018 #define _BUNDLE_H_ 00019 00020 #include <sys/time.h> 00021 00022 #include <oasys/debug/Formatter.h> 00023 #include <oasys/debug/DebugUtils.h> 00024 #include <oasys/serialize/Serialize.h> 00025 #include <oasys/thread/SpinLock.h> 00026 #include <oasys/util/StringBuffer.h> 00027 00028 #include "BlockInfo.h" 00029 #include "BundleMappings.h" 00030 #include "BundlePayload.h" 00031 #include "BundleTimestamp.h" 00032 #include "CustodyTimer.h" 00033 #include "ForwardingLog.h" 00034 #include "MetadataBlock.h" 00035 #include "SequenceID.h" 00036 #include "naming/EndpointID.h" 00037 00038 namespace dtn { 00039 00040 class BundleList; 00041 class BundleStore; 00042 class ExpirationTimer; 00043 class SQLBundleStore; 00044 00066 class Bundle : public oasys::Formatter, public oasys::SerializableObject 00067 { 00068 public: 00077 Bundle(BundlePayload::location_t location = BundlePayload::DISK); 00078 00082 Bundle(const oasys::Builder&); 00083 00087 virtual ~Bundle(); 00088 00093 void copy_metadata(Bundle* new_bundle) const; 00094 00098 int format(char* buf, size_t sz) const; 00099 00103 void format_verbose(oasys::StringBuffer* buf); 00104 00108 void serialize(oasys::SerializeAction* a); 00109 00114 u_int32_t durable_key() { return bundleid_; } 00115 00121 size_t durable_size() { return payload_.length(); } 00122 00129 int refcount() { return refcount_; } 00130 00136 int add_ref(const char* what1, const char* what2 = ""); 00137 00145 int del_ref(const char* what1, const char* what2 = ""); 00146 00150 size_t num_mappings(); 00151 00156 BundleMappings* mappings(); 00157 00161 bool is_queued_on(const BundleList* l); 00162 00166 bool validate(oasys::StringBuffer* errbuf); 00167 00171 bool receipt_requested() const 00172 { 00173 return (receive_rcpt_ || custody_rcpt_ || forward_rcpt_ || 00174 delivery_rcpt_ || deletion_rcpt_); 00175 } 00176 00180 typedef enum { 00181 COS_INVALID = -1, 00182 COS_BULK = 0, 00183 COS_NORMAL = 1, 00184 COS_EXPEDITED = 2, 00185 COS_RESERVED = 3 00186 } priority_values_t; 00187 00191 static const char* prioritytoa(u_int8_t priority) { 00192 switch (priority) { 00193 case COS_BULK: return "BULK"; 00194 case COS_NORMAL: return "NORMAL"; 00195 case COS_EXPEDITED: return "EXPEDITED"; 00196 default: return "_UNKNOWN_PRIORITY_"; 00197 } 00198 } 00199 00201 u_int32_t bundleid() const { return bundleid_; } 00202 oasys::Lock* lock() const { return &lock_; } 00203 bool expired() const { return expiration_timer_ == NULL; } 00204 const EndpointID& source() const { return source_; } 00205 const EndpointID& dest() const { return dest_; } 00206 const EndpointID& custodian() const { return custodian_; } 00207 const EndpointID& replyto() const { return replyto_; } 00208 const EndpointID& prevhop() const { return prevhop_; } 00209 bool is_fragment() const { return is_fragment_; } 00210 bool is_admin() const { return is_admin_; } 00211 bool do_not_fragment() const { return do_not_fragment_; } 00212 bool custody_requested() const { return custody_requested_; } 00213 bool singleton_dest() const { return singleton_dest_; } 00214 u_int8_t priority() const { return priority_; } 00215 bool receive_rcpt() const { return receive_rcpt_; } 00216 bool custody_rcpt() const { return custody_rcpt_; } 00217 bool forward_rcpt() const { return forward_rcpt_; } 00218 bool delivery_rcpt() const { return delivery_rcpt_; } 00219 bool deletion_rcpt() const { return deletion_rcpt_; } 00220 bool app_acked_rcpt() const { return app_acked_rcpt_; } 00221 u_int32_t expiration() const { return expiration_; } 00222 u_int32_t frag_offset() const { return frag_offset_; } 00223 u_int32_t orig_length() const { return orig_length_; } 00224 bool in_datastore() const { return in_datastore_; } 00225 bool local_custody() const { return local_custody_; } 00226 const std::string& owner() const { return owner_; } 00227 bool fragmented_incoming() const { return fragmented_incoming_; } 00228 const SequenceID& sequence_id() const { return sequence_id_; } 00229 const SequenceID& obsoletes_id() const { return obsoletes_id_; } 00230 const EndpointID& session_eid() const { return session_eid_; } 00231 u_int8_t session_flags() const { return session_flags_; } 00232 const BundlePayload& payload() const { return payload_; } 00233 const ForwardingLog* fwdlog() const { return &fwdlog_; } 00234 const BundleTimestamp& creation_ts() const { return creation_ts_; } 00235 const BundleTimestamp& extended_id() const { return extended_id_; } 00236 const BlockInfoVec& recv_blocks() const { return recv_blocks_; } 00237 const MetadataVec& recv_metadata() const { return recv_metadata_; } 00238 const LinkMetadataSet& generated_metadata() const { return generated_metadata_; } 00240 00242 EndpointID* mutable_source() { return &source_; } 00243 EndpointID* mutable_dest() { return &dest_; } 00244 EndpointID* mutable_replyto() { return &replyto_; } 00245 EndpointID* mutable_custodian() { return &custodian_; } 00246 EndpointID* mutable_prevhop() { return &prevhop_; } 00247 void set_is_fragment(bool t) { is_fragment_ = t; } 00248 void set_is_admin(bool t) { is_admin_ = t; } 00249 void set_do_not_fragment(bool t) { do_not_fragment_ = t; } 00250 void set_custody_requested(bool t) { custody_requested_ = t; } 00251 void set_singleton_dest(bool t) { singleton_dest_ = t; } 00252 void set_priority(u_int8_t p) { priority_ = p; } 00253 void set_receive_rcpt(bool t) { receive_rcpt_ = t; } 00254 void set_custody_rcpt(bool t) { custody_rcpt_ = t; } 00255 void set_forward_rcpt(bool t) { forward_rcpt_ = t; } 00256 void set_delivery_rcpt(bool t) { delivery_rcpt_ = t; } 00257 void set_deletion_rcpt(bool t) { deletion_rcpt_ = t; } 00258 void set_app_acked_rcpt(bool t) { app_acked_rcpt_ = t; } 00259 void set_expiration(u_int32_t e) { expiration_ = e; } 00260 void set_frag_offset(u_int32_t o) { frag_offset_ = o; } 00261 void set_orig_length(u_int32_t l) { orig_length_ = l; } 00262 void set_in_datastore(bool t) { in_datastore_ = t; } 00263 void set_local_custody(bool t) { local_custody_ = t; } 00264 void set_owner(const std::string& s) { owner_ = s; } 00265 void set_fragmented_incoming(bool t) { fragmented_incoming_ = t; } 00266 void set_creation_ts(const BundleTimestamp& ts) { creation_ts_ = ts; } 00267 SequenceID* mutable_sequence_id() { return &sequence_id_; } 00268 SequenceID* mutable_obsoletes_id() { return &obsoletes_id_; } 00269 EndpointID* mutable_session_eid() { return &session_eid_; } 00270 void set_session_flags(u_int8_t f) { session_flags_ = f; } 00271 void test_set_bundleid(u_int32_t id) { bundleid_ = id; } 00272 BundlePayload* mutable_payload() { return &payload_; } 00273 ForwardingLog* fwdlog() { return &fwdlog_; } 00274 ExpirationTimer* expiration_timer(){ return expiration_timer_; } 00275 CustodyTimerVec* custody_timers() { return &custody_timers_; } 00276 BlockInfoVec* api_blocks() { return &api_blocks_; } 00277 LinkBlockSet* xmit_blocks() { return &xmit_blocks_; } 00278 BlockInfoVec* mutable_recv_blocks() { return &recv_blocks_; } 00279 MetadataVec* mutable_recv_metadata() { return &recv_metadata_; } 00280 LinkMetadataSet* mutable_generated_metadata() { 00281 return &generated_metadata_; 00282 } 00283 void set_expiration_timer(ExpirationTimer* e) { 00284 expiration_timer_ = e; 00285 } 00287 00288 private: 00289 /* 00290 * Bundle data fields that correspond to data transferred between 00291 * nodes according to the bundle protocol. 00292 */ 00293 EndpointID source_; 00294 EndpointID dest_; 00295 EndpointID custodian_; 00296 EndpointID replyto_; 00297 EndpointID prevhop_; 00298 bool is_fragment_; 00299 bool is_admin_; 00300 bool do_not_fragment_; 00301 bool custody_requested_; 00302 bool singleton_dest_; 00303 u_int8_t priority_; 00304 bool receive_rcpt_; 00305 bool custody_rcpt_; 00306 bool forward_rcpt_; 00307 bool delivery_rcpt_; 00308 bool deletion_rcpt_; 00309 bool app_acked_rcpt_; 00310 BundleTimestamp creation_ts_; 00311 u_int32_t expiration_; 00312 u_int32_t frag_offset_; 00313 u_int32_t orig_length_; 00314 SequenceID sequence_id_; 00315 SequenceID obsoletes_id_; 00316 EndpointID session_eid_; 00317 u_int8_t session_flags_; 00318 BundlePayload payload_; 00319 00320 /* 00321 * Internal fields and structures for managing the bundle that are 00322 * not transmitted over the network. 00323 */ 00324 u_int32_t bundleid_; 00325 mutable oasys::SpinLock lock_; 00326 00327 bool in_datastore_; 00328 bool local_custody_; 00329 std::string owner_; 00330 00331 BundleTimestamp extended_id_; 00332 00333 ForwardingLog fwdlog_; 00334 ExpirationTimer* expiration_timer_; 00335 CustodyTimerVec custody_timers_; 00336 bool fragmented_incoming_; 00337 00338 00339 BlockInfoVec recv_blocks_; 00340 BlockInfoVec api_blocks_; 00341 LinkBlockSet xmit_blocks_; 00342 00343 MetadataVec recv_metadata_; 00344 LinkMetadataSet generated_metadata_; 00345 00346 BundleMappings mappings_; 00347 00348 00349 int refcount_; 00350 bool freed_; 00351 00352 00356 void init(u_int32_t id); 00357 }; 00358 00359 00360 } // namespace dtn 00361 00362 #endif /* _BUNDLE_H_ */