BundleDaemon.h

Go to the documentation of this file.
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_DAEMON_H_
00039 #define _BUNDLE_DAEMON_H_
00040 
00041 #include <vector>
00042 
00043 #include <oasys/compat/inttypes.h>
00044 #include <oasys/debug/Log.h>
00045 #include <oasys/thread/Thread.h>
00046 #include <oasys/thread/MsgQueue.h>
00047 #include <oasys/util/StringBuffer.h>
00048 
00049 #include "BundleEvent.h"
00050 #include "BundleEventHandler.h"
00051 #include "BundleProtocol.h"
00052 
00053 namespace dtn {
00054 
00055 class AdminRegistration;
00056 class Bundle;
00057 class BundleAction;
00058 class BundleActions;
00059 class BundleList;
00060 class BundleRouter;
00061 class ContactManager;
00062 class FragmentManager;
00063 class RegistrationTable;
00064 
00072 class BundleDaemon : public BundleEventHandler, public oasys::Thread {
00073 public:
00077     static BundleDaemon* instance() {
00078         if (instance_ == NULL) {
00079             PANIC("BundleDaemon::init not called yet");
00080         }
00081         return instance_;
00082     }
00083 
00087     BundleDaemon();
00088 
00094     virtual void do_init();
00095     
00099     static void init()
00100     {       
00101         if (instance_ != NULL) 
00102         {
00103             PANIC("BundleDaemon already initialized");
00104         }
00105 
00106         instance_ = new BundleDaemon();     
00107         instance_->do_init();
00108     }
00109 
00114     static void post(BundleEvent* event);
00115  
00120     static void post_at_head(BundleEvent* event);
00121     
00126     static bool post_and_wait(BundleEvent* event,
00127                               oasys::Notifier* notifier,
00128                               int timeout = -1, bool at_back = true);
00129     
00134     virtual void post_event(BundleEvent* event, bool at_back = true);
00135 
00139     BundleRouter* router()
00140     {
00141         ASSERT(router_ != NULL);
00142         return router_;
00143     }
00144 
00148     BundleActions* actions() { return actions_; }
00149 
00153     ContactManager* contactmgr() { return contactmgr_; }
00154 
00158     FragmentManager* fragmentmgr() { return fragmentmgr_; }
00159 
00163     const RegistrationTable* reg_table() { return reg_table_; }
00164 
00168     BundleList* pending_bundles() { return pending_bundles_; }
00169     
00173     BundleList* custody_bundles() { return custody_bundles_; }
00174     
00178     void get_routing_state(oasys::StringBuffer* buf);
00179 
00184     void get_bundle_stats(oasys::StringBuffer* buf);
00185 
00190     void get_daemon_stats(oasys::StringBuffer* buf);
00191 
00195     void reset_stats();
00196 
00200     const EndpointID& local_eid() { return local_eid_; }
00201 
00205     void set_local_eid(const char* eid_str) {
00206         local_eid_.assign(eid_str);
00207     }
00208 
00212     struct Params {
00215         bool early_deletion_;
00216 
00218         bool accept_custody_;
00219 
00221         bool reactive_frag_enabled_;
00222         
00224         bool retry_reliable_unacked_;
00225 
00227         size_t proactive_frag_threshold_;
00228 
00230         bool test_permuted_delivery_;
00231     };
00232 
00233     static Params params_;
00234 
00238     typedef void (*ShutdownProc) (void* args);
00239     
00243     void set_app_shutdown(ShutdownProc proc, void* data)
00244     {
00245         app_shutdown_proc_ = proc;
00246         app_shutdown_data_ = data;
00247     }
00248     
00249 protected:
00253     void load_registrations();
00254         
00258     void load_bundles();
00259         
00263     void run();
00264 
00268     void handle_event(BundleEvent* event);
00269 
00271 
00274     void handle_bundle_received(BundleReceivedEvent* event);
00275     void handle_bundle_transmitted(BundleTransmittedEvent* event);
00276     void handle_bundle_transmit_failed(BundleTransmitFailedEvent* event);
00277     void handle_bundle_delivered(BundleDeliveredEvent* event);
00278     void handle_bundle_expired(BundleExpiredEvent* event);
00279     void handle_bundle_free(BundleFreeEvent* event);
00280     void handle_registration_added(RegistrationAddedEvent* event);
00281     void handle_registration_removed(RegistrationRemovedEvent* event);
00282     void handle_registration_expired(RegistrationExpiredEvent* event);
00283     void handle_contact_up(ContactUpEvent* event);
00284     void handle_contact_down(ContactDownEvent* event);
00285     void handle_link_available(LinkAvailableEvent* event);    
00286     void handle_link_unavailable(LinkUnavailableEvent* event);
00287     void handle_link_state_change_request(LinkStateChangeRequest* request);
00288     void handle_reassembly_completed(ReassemblyCompletedEvent* event);
00289     void handle_route_add(RouteAddEvent* event);
00290     void handle_route_del(RouteDelEvent* event);
00291     void handle_custody_signal(CustodySignalEvent* event);
00292     void handle_custody_timeout(CustodyTimeoutEvent* event);
00293     void handle_shutdown_request(ShutdownRequest* event);
00294     void handle_status_request(StatusRequest* event);
00296 
00297     typedef BundleProtocol::custody_signal_reason_t custody_signal_reason_t;
00298     typedef BundleProtocol::status_report_flag_t status_report_flag_t;
00299     typedef BundleProtocol::status_report_reason_t status_report_reason_t;
00300     
00304     void generate_status_report(Bundle* bundle,
00305                                 status_report_flag_t flag,
00306                                 status_report_reason_t reason =
00307                                 BundleProtocol::REASON_NO_ADDTL_INFO);
00308 
00312     void generate_custody_signal(Bundle* bundle, bool succeeded,
00313                                  custody_signal_reason_t reason);
00314     
00318     void cancel_custody_timers(Bundle* bundle);
00319 
00324     void accept_custody(Bundle* bundle);
00325 
00330     void release_custody(Bundle* bundle);
00331 
00339     bool add_to_pending(Bundle* bundle, bool add_to_store);
00340     
00345     void delete_from_pending(Bundle* bundle, status_report_reason_t reason);
00346 
00352     void try_delete_from_pending(Bundle* bundle);
00353 
00359     Bundle* find_duplicate(Bundle* bundle);
00360 
00364     void deliver_to_registration(Bundle* bundle, Registration* registration);
00365     
00370     void check_registrations(Bundle* bundle);
00371     
00373     BundleRouter* router_;
00374 
00376     BundleActions* actions_;
00377 
00379     AdminRegistration* admin_reg_;
00380 
00382     ContactManager* contactmgr_;
00383 
00385     FragmentManager* fragmentmgr_;
00386 
00388     RegistrationTable* reg_table_;
00389 
00391     BundleList* pending_bundles_;
00392 
00394     BundleList* custody_bundles_;
00395     
00397     oasys::MsgQueue<BundleEvent*>* eventq_;
00398 
00401     EndpointID local_eid_;
00402 
00404     struct Stats {
00405         u_int32_t bundles_received_;
00406         u_int32_t bundles_delivered_;
00407         u_int32_t bundles_generated_;
00408         u_int32_t bundles_transmitted_;
00409         u_int32_t bundles_expired_;
00410         u_int32_t duplicate_bundles_;
00411         u_int32_t events_processed_;
00412     };
00413 
00415     Stats stats_;
00416 
00418     ShutdownProc app_shutdown_proc_;
00419  
00421     void* app_shutdown_data_;
00422 
00424     static BundleDaemon* instance_;
00425 };
00426 
00427 } // namespace dtn
00428 
00429 #endif /* _BUNDLE_DAEMON_H_ */

Generated on Fri Dec 22 14:47:58 2006 for DTN Reference Implementation by  doxygen 1.5.1