Bundle.h

Go to the documentation of this file.
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 <set>
00021 #include <sys/time.h>
00022 
00023 #include <oasys/debug/Formatter.h>
00024 #include <oasys/debug/DebugUtils.h>
00025 #include <oasys/serialize/Serialize.h>
00026 #include <oasys/thread/SpinLock.h>
00027 #include <oasys/util/StringBuffer.h>
00028 
00029 #include "BlockInfo.h"
00030 #include "BundlePayload.h"
00031 #include "BundleTimestamp.h"
00032 #include "CustodyTimer.h"
00033 #include "ForwardingLog.h"
00034 #include "naming/EndpointID.h"
00035 
00036 
00037 namespace dtn {
00038 
00039 class BundleList;
00040 class BundleStore;
00041 class ExpirationTimer;
00042 class SQLBundleStore;
00043 
00065 class Bundle : public oasys::Formatter, public oasys::SerializableObject
00066 {
00067 public:
00075     Bundle(BundlePayload::location_t location = BundlePayload::UNDETERMINED);
00076 
00080     Bundle(const oasys::Builder&);
00081 
00085     virtual ~Bundle();
00086 
00091     void copy_metadata(Bundle* new_bundle);
00092 
00096     int format(char* buf, size_t sz) const;
00097     
00101     void format_verbose(oasys::StringBuffer* buf);
00102     
00106     void serialize(oasys::SerializeAction* a);
00107 
00112     u_int32_t durable_key() { return bundleid_; }
00113 
00119     size_t durable_size() { return payload_.length(); }
00120     
00127     int refcount() { return refcount_; }
00128 
00134     int add_ref(const char* what1, const char* what2 = "");
00135 
00143     int del_ref(const char* what1, const char* what2 = "");
00144 
00145     /*
00146      * Types used for the mapping table.
00147      */
00148     typedef std::set<BundleList*> BundleMappings;
00149     typedef BundleMappings::const_iterator MappingsIterator;
00150     
00154     int num_mappings() { return mappings_.size(); }
00155 
00159     MappingsIterator mappings_begin();
00160     
00164     MappingsIterator mappings_end();
00165 
00169     bool is_queued_on(BundleList* l);
00170 
00174     bool validate(oasys::StringBuffer* errbuf);
00175 
00179     bool receipt_requested()
00180     {
00181         return (receive_rcpt_ || custody_rcpt_ || forward_rcpt_ ||
00182                 delivery_rcpt_ || deletion_rcpt_);
00183     }
00184     
00188     typedef enum {
00189         COS_BULK      = 0,              
00190         COS_NORMAL    = 1,              
00191         COS_EXPEDITED = 2,              
00192         COS_RESERVED  = 3               
00193     } priority_values_t;
00194 
00198     static const char* prioritytoa(u_int8_t priority) {
00199         switch (priority) {
00200         case COS_BULK:          return "BULK";
00201         case COS_NORMAL:        return "NORMAL";
00202         case COS_EXPEDITED:     return "EXPEDITED";
00203         default:                return "_UNKNOWN_PRIORITY_";
00204         }
00205     }
00206 
00207     /*
00208      * Bundle data fields that correspond to data transferred between
00209      * nodes according to the bundle protocol (all public to avoid the
00210      * need for accessor functions).
00211      */
00212     EndpointID source_;         
00213     EndpointID dest_;           
00214     EndpointID custodian_;      
00215     EndpointID replyto_;        
00216     EndpointID prevhop_;        
00217     bool is_fragment_;          
00218     bool is_admin_;             
00219     bool do_not_fragment_;      
00220     bool custody_requested_;    
00221     bool singleton_dest_;       
00222     u_int8_t priority_;         
00223     bool receive_rcpt_;         
00224     bool custody_rcpt_;         
00225     bool forward_rcpt_;         
00226     bool delivery_rcpt_;        
00227     bool deletion_rcpt_;        
00228     bool app_acked_rcpt_;       
00229     BundleTimestamp creation_ts_; 
00230     u_int32_t expiration_;      
00231     u_int32_t frag_offset_;     
00232     u_int32_t orig_length_;     
00233     BundlePayload payload_;     
00234 
00235     /*
00236      * Internal fields and structures for managing the bundle that are
00237      * not transmitted over the network.
00238      */
00239     u_int32_t bundleid_;        
00240     oasys::SpinLock lock_;      
00241 
00242     bool in_datastore_;         
00243     bool local_custody_;        
00244     std::string owner_;         
00245 
00246     ForwardingLog fwdlog_;      
00247     ExpirationTimer* expiration_timer_; 
00248     CustodyTimerVec custody_timers_; 
00249 
00250     BlockInfoVec recv_blocks_;  
00251     BlockInfoVec api_blocks_;   
00252     LinkBlockSet xmit_blocks_;  
00253 protected:
00254     friend class BundleList;
00255     
00256     /*
00257      * Protected fields.
00258      */
00259     BundleMappings mappings_;   
00260 
00261     
00262     int  refcount_;             
00263     bool freed_;                
00264 
00265 
00266 private:
00270     void init(u_int32_t id);
00271 };
00272 
00273 
00274 } // namespace dtn
00275 
00276 #endif /* _BUNDLE_H_ */

Generated on Thu Jun 7 16:56:48 2007 for DTN Reference Implementation by  doxygen 1.5.1