00001 /* 00002 * IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. By 00003 * downloading, copying, installing or using the software you agree to 00004 * this license. If you do not agree to this license, do not download, 00005 * install, copy or use the software. 00006 * 00007 * Intel Open Source License 00008 * 00009 * Copyright (c) 2004 Intel Corporation. All rights reserved. 00010 * 00011 * Redistribution and use in source and binary forms, with or without 00012 * modification, are permitted provided that the following conditions are 00013 * met: 00014 * 00015 * Redistributions of source code must retain the above copyright 00016 * notice, this list of conditions and the following disclaimer. 00017 * 00018 * Redistributions in binary form must reproduce the above copyright 00019 * notice, this list of conditions and the following disclaimer in the 00020 * documentation and/or other materials provided with the distribution. 00021 * 00022 * Neither the name of the Intel Corporation nor the names of its 00023 * contributors may be used to endorse or promote products derived from 00024 * this software without specific prior written permission. 00025 * 00026 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00027 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00028 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00029 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR 00030 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00031 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00032 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00033 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00034 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00035 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00036 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00037 */ 00038 #ifndef _BUNDLE_H_ 00039 #define _BUNDLE_H_ 00040 00041 #include <set> 00042 #include <sys/time.h> 00043 00044 #include <oasys/debug/Formatter.h> 00045 #include <oasys/debug/DebugUtils.h> 00046 #include <oasys/serialize/Serialize.h> 00047 #include <oasys/thread/SpinLock.h> 00048 #include <oasys/util/StringBuffer.h> 00049 00050 #include "BundlePayload.h" 00051 #include "BundleTimestamp.h" 00052 #include "CustodyTimer.h" 00053 #include "ForwardingLog.h" 00054 #include "naming/EndpointID.h" 00055 00056 00057 namespace dtn { 00058 00059 class BundleList; 00060 class BundleStore; 00061 class ExpirationTimer; 00062 class SQLBundleStore; 00063 00085 class Bundle : public oasys::Formatter, public oasys::SerializableObject 00086 { 00087 public: 00092 Bundle(); 00093 00097 Bundle(const oasys::Builder&); 00098 00102 virtual ~Bundle(); 00103 00108 void copy_metadata(Bundle* new_bundle); 00109 00113 int format(char* buf, size_t sz) const; 00114 00118 void format_verbose(oasys::StringBuffer* buf); 00119 00123 void serialize(oasys::SerializeAction* a); 00124 00129 u_int32_t durable_key() { return bundleid_; } 00130 00137 int refcount() { return refcount_; } 00138 00144 int add_ref(const char* what1, const char* what2 = ""); 00145 00153 int del_ref(const char* what1, const char* what2 = ""); 00154 00155 /* 00156 * Types used for the mapping table. 00157 */ 00158 typedef std::set<BundleList*> BundleMappings; 00159 typedef BundleMappings::const_iterator MappingsIterator; 00160 00164 int num_mappings() { return mappings_.size(); } 00165 00169 MappingsIterator mappings_begin(); 00170 00174 MappingsIterator mappings_end(); 00175 00179 bool is_queued_on(BundleList* l); 00180 00184 bool validate(oasys::StringBuffer* errbuf); 00185 00189 bool receipt_requested() 00190 { 00191 return (receive_rcpt_ || custody_rcpt_ || forward_rcpt_ || 00192 delivery_rcpt_ || delivery_rcpt_); 00193 } 00194 00198 typedef enum { 00199 COS_BULK = 0, 00200 COS_NORMAL = 1, 00201 COS_EXPEDITED = 2, 00202 COS_RESERVED = 3 00203 } priority_values_t; 00204 00208 static const char* prioritytoa(u_int8_t priority) { 00209 switch (priority) { 00210 case COS_BULK: return "BULK"; 00211 case COS_NORMAL: return "NORMAL"; 00212 case COS_EXPEDITED: return "EXPEDITED"; 00213 default: return "_UNKNOWN_PRIORITY_"; 00214 } 00215 } 00216 00217 /* 00218 * Bundle data fields that correspond to data transferred between 00219 * nodes according to the bundle protocol (all public to avoid the 00220 * need for accessor functions). 00221 */ 00222 EndpointID source_; 00223 EndpointID dest_; 00224 EndpointID custodian_; 00225 EndpointID replyto_; 00226 bool is_fragment_; 00227 bool is_admin_; 00228 bool do_not_fragment_; 00229 bool custody_requested_; 00230 bool singleton_dest_; 00231 u_int8_t priority_; 00232 bool receive_rcpt_; 00233 bool custody_rcpt_; 00234 bool forward_rcpt_; 00235 bool delivery_rcpt_; 00236 bool deletion_rcpt_; 00237 bool app_acked_rcpt_; 00238 BundleTimestamp creation_ts_; 00239 u_int32_t expiration_; 00240 u_int32_t frag_offset_; 00241 u_int32_t orig_length_; 00242 BundlePayload payload_; 00243 00244 /* 00245 * Internal fields and structures for managing the bundle that are 00246 * not transmitted over the network. 00247 */ 00248 u_int32_t bundleid_; 00249 oasys::SpinLock lock_; 00250 00251 bool in_datastore_; 00252 bool local_custody_; 00253 std::string owner_; 00254 00255 ForwardingLog fwdlog_; 00256 ExpirationTimer* expiration_timer_; 00257 CustodyTimerVec custody_timers_; 00258 00259 protected: 00260 friend class BundleList; 00261 00262 /* 00263 * Protected fields. 00264 */ 00265 BundleMappings mappings_; 00266 00267 00268 int refcount_; 00269 bool freed_; 00270 00271 00272 private: 00276 void init(u_int32_t id); 00277 }; 00278 00279 00280 } // namespace dtn 00281 00282 #endif /* _BUNDLE_H_ */