00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
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 }
00428
00429 #endif