00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _BUNDLE_DAEMON_H_
00018 #define _BUNDLE_DAEMON_H_
00019
00020 #include <vector>
00021
00022 #include <oasys/compat/inttypes.h>
00023 #include <oasys/debug/Log.h>
00024 #include <oasys/tclcmd/IdleTclExit.h>
00025 #include <oasys/thread/Timer.h>
00026 #include <oasys/thread/Thread.h>
00027 #include <oasys/thread/MsgQueue.h>
00028 #include <oasys/util/StringBuffer.h>
00029 #include <oasys/util/Time.h>
00030
00031 #include "BundleEvent.h"
00032 #include "BundleEventHandler.h"
00033 #include "BundleProtocol.h"
00034 #include "BundleActions.h"
00035 #include "BundleStatusReport.h"
00036
00037 namespace dtn {
00038
00039 class AdminRegistration;
00040 class Bundle;
00041 class BundleAction;
00042 class BundleActions;
00043 class BundleList;
00044 class BundleRouter;
00045 class ContactManager;
00046 class FragmentManager;
00047 class PingRegistration;
00048 class RegistrationTable;
00049
00057 class BundleDaemon : public oasys::Singleton<BundleDaemon, false>,
00058 public BundleEventHandler,
00059 public oasys::Thread
00060 {
00061 public:
00065 BundleDaemon();
00066
00070 virtual ~BundleDaemon();
00071
00077 virtual void do_init();
00078
00082 static void init()
00083 {
00084 if (instance_ != NULL)
00085 {
00086 PANIC("BundleDaemon already initialized");
00087 }
00088
00089 instance_ = new BundleDaemon();
00090 instance_->do_init();
00091 }
00092
00098 virtual size_t event_queue_size()
00099 {
00100 return eventq_->size();
00101 }
00102
00107 static void post(BundleEvent* event);
00108
00113 static void post_at_head(BundleEvent* event);
00114
00119 static bool post_and_wait(BundleEvent* event,
00120 oasys::Notifier* notifier,
00121 int timeout = -1, bool at_back = true);
00122
00127 virtual void post_event(BundleEvent* event, bool at_back = true);
00128
00132 BundleRouter* router()
00133 {
00134 ASSERT(router_ != NULL);
00135 return router_;
00136 }
00137
00141 BundleActions* actions() { return actions_; }
00142
00146 ContactManager* contactmgr() { return contactmgr_; }
00147
00151 FragmentManager* fragmentmgr() { return fragmentmgr_; }
00152
00156 const RegistrationTable* reg_table() { return reg_table_; }
00157
00161 BundleList* pending_bundles() { return pending_bundles_; }
00162
00166 BundleList* custody_bundles() { return custody_bundles_; }
00167
00171 void get_routing_state(oasys::StringBuffer* buf);
00172
00177 void get_bundle_stats(oasys::StringBuffer* buf);
00178
00183 void get_daemon_stats(oasys::StringBuffer* buf);
00184
00188 void reset_stats();
00189
00193 const EndpointID& local_eid() { return local_eid_; }
00194
00198 void set_local_eid(const char* eid_str) {
00199 local_eid_.assign(eid_str);
00200 }
00201
00205 struct Params {
00207 Params();
00208
00211 bool early_deletion_;
00212
00215 bool suppress_duplicates_;
00216
00218 bool accept_custody_;
00219
00221 bool reactive_frag_enabled_;
00222
00224 bool retry_reliable_unacked_;
00225
00227 bool test_permuted_delivery_;
00228
00230 bool injected_bundles_in_memory_;
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
00252 void set_rtr_shutdown(ShutdownProc proc, void* data)
00253 {
00254 rtr_shutdown_proc_ = proc;
00255 rtr_shutdown_data_ = data;
00256 }
00257
00261 static bool shutting_down()
00262 {
00263 return shutting_down_;
00264 }
00265
00271 void init_idle_shutdown(int interval);
00272
00276 void check_and_deliver_to_registrations(Bundle* bundle, const EndpointID&);
00277
00278 protected:
00279 friend class BundleActions;
00280
00284 void load_registrations();
00285
00289 void load_bundles();
00290
00294 void run();
00295
00299 void handle_event(BundleEvent* event);
00300
00302
00305 void handle_bundle_received(BundleReceivedEvent* event);
00306 void handle_bundle_transmitted(BundleTransmittedEvent* event);
00307 void handle_bundle_delivered(BundleDeliveredEvent* event);
00308 void handle_bundle_expired(BundleExpiredEvent* event);
00309 void handle_bundle_free(BundleFreeEvent* event);
00310 void handle_bundle_send(BundleSendRequest* event);
00311 void handle_bundle_cancel(BundleCancelRequest* event);
00312 void handle_bundle_cancelled(BundleSendCancelledEvent* event);
00313 void handle_bundle_inject(BundleInjectRequest* event);
00314 void handle_bundle_delete(BundleDeleteRequest* request);
00315 void handle_bundle_accept(BundleAcceptRequest* event);
00316 void handle_bundle_query(BundleQueryRequest* event);
00317 void handle_bundle_report(BundleReportEvent* event);
00318 void handle_bundle_attributes_query(BundleAttributesQueryRequest* request);
00319 void handle_bundle_attributes_report(BundleAttributesReportEvent* event);
00320 void handle_registration_added(RegistrationAddedEvent* event);
00321 void handle_registration_removed(RegistrationRemovedEvent* event);
00322 void handle_registration_expired(RegistrationExpiredEvent* event);
00323 void handle_registration_delete(RegistrationDeleteRequest* request);
00324 void handle_contact_up(ContactUpEvent* event);
00325 void handle_contact_down(ContactDownEvent* event);
00326 void handle_contact_query(ContactQueryRequest* event);
00327 void handle_contact_report(ContactReportEvent* event);
00328 void handle_link_created(LinkCreatedEvent* event);
00329 void handle_link_deleted(LinkDeletedEvent* event);
00330 void handle_link_available(LinkAvailableEvent* event);
00331 void handle_link_unavailable(LinkUnavailableEvent* event);
00332 void handle_link_state_change_request(LinkStateChangeRequest* request);
00333 void handle_link_create(LinkCreateRequest* event);
00334 void handle_link_delete(LinkDeleteRequest* request);
00335 void handle_link_reconfigure(LinkReconfigureRequest* request);
00336 void handle_link_query(LinkQueryRequest* event);
00337 void handle_link_report(LinkReportEvent* event);
00338 void handle_reassembly_completed(ReassemblyCompletedEvent* event);
00339 void handle_route_add(RouteAddEvent* event);
00340 void handle_route_del(RouteDelEvent* event);
00341 void handle_route_query(RouteQueryRequest* event);
00342 void handle_route_report(RouteReportEvent* event);
00343 void handle_custody_signal(CustodySignalEvent* event);
00344 void handle_custody_timeout(CustodyTimeoutEvent* event);
00345 void handle_shutdown_request(ShutdownRequest* event);
00346 void handle_status_request(StatusRequest* event);
00347 void handle_cla_set_params(CLASetParamsRequest* request);
00348 void handle_bundle_queued_query(BundleQueuedQueryRequest* request);
00349 void handle_bundle_queued_report(BundleQueuedReportEvent* event);
00350 void handle_eid_reachable_query(EIDReachableQueryRequest* request);
00351 void handle_eid_reachable_report(EIDReachableReportEvent* event);
00352 void handle_link_attribute_changed(LinkAttributeChangedEvent* event);
00353 void handle_link_attributes_query(LinkAttributesQueryRequest* request);
00354 void handle_link_attributes_report(LinkAttributesReportEvent* event);
00355 void handle_iface_attributes_query(IfaceAttributesQueryRequest* request);
00356 void handle_iface_attributes_report(IfaceAttributesReportEvent* event);
00357 void handle_cla_parameters_query(CLAParametersQueryRequest* request);
00358 void handle_cla_parameters_report(CLAParametersReportEvent* event);
00360
00362 void event_handlers_completed(BundleEvent* event);
00364
00365 typedef BundleProtocol::custody_signal_reason_t custody_signal_reason_t;
00366 typedef BundleProtocol::status_report_flag_t status_report_flag_t;
00367 typedef BundleProtocol::status_report_reason_t status_report_reason_t;
00368
00372 void generate_status_report(Bundle* bundle,
00373 BundleStatusReport::flag_t flag,
00374 status_report_reason_t reason =
00375 BundleProtocol::REASON_NO_ADDTL_INFO);
00376
00380 void generate_custody_signal(Bundle* bundle, bool succeeded,
00381 custody_signal_reason_t reason);
00382
00386 void cancel_custody_timers(Bundle* bundle);
00387
00392 void accept_custody(Bundle* bundle);
00393
00398 void release_custody(Bundle* bundle);
00399
00407 bool add_to_pending(Bundle* bundle, bool add_to_store);
00408
00413 bool delete_from_pending(const BundleRef& bundle);
00414
00420 bool try_to_delete(const BundleRef& bundle);
00421
00428 bool delete_bundle(const BundleRef& bundle,
00429 status_report_reason_t reason =
00430 BundleProtocol::REASON_NO_ADDTL_INFO);
00431
00437 Bundle* find_duplicate(Bundle* bundle);
00438
00442 void deliver_to_registration(Bundle* bundle, Registration* registration);
00443
00451 bool check_local_delivery(Bundle* bundle, bool deliver);
00452
00454 BundleRouter* router_;
00455
00457 BundleActions* actions_;
00458
00460 AdminRegistration* admin_reg_;
00461
00463 PingRegistration* ping_reg_;
00464
00466 ContactManager* contactmgr_;
00467
00469 FragmentManager* fragmentmgr_;
00470
00472 RegistrationTable* reg_table_;
00473
00475 BundleList* pending_bundles_;
00476
00478 BundleList* custody_bundles_;
00479
00481 oasys::MsgQueue<BundleEvent*>* eventq_;
00482
00485 EndpointID local_eid_;
00486
00488 struct Stats {
00489 u_int32_t received_bundles_;
00490 u_int32_t delivered_bundles_;
00491 u_int32_t generated_bundles_;
00492 u_int32_t transmitted_bundles_;
00493 u_int32_t expired_bundles_;
00494 u_int32_t deleted_bundles_;
00495 u_int32_t duplicate_bundles_;
00496 u_int32_t injected_bundles_;
00497 u_int32_t events_processed_;
00498 };
00499
00501 Stats stats_;
00502
00504 ShutdownProc app_shutdown_proc_;
00505
00507 void* app_shutdown_data_;
00508
00510 ShutdownProc rtr_shutdown_proc_;
00511
00513 void* rtr_shutdown_data_;
00514
00515
00516 static bool shutting_down_;
00517
00519 struct DaemonIdleExit : public oasys::IdleTclExit {
00520 DaemonIdleExit(int interval) : IdleTclExit(interval) {}
00521 bool is_idle(const struct timeval& now);
00522 };
00523 friend class DaemonIdleExit;
00524
00526 DaemonIdleExit* idle_exit_;
00527
00529 oasys::Time last_event_;
00530 };
00531
00532 }
00533
00534 #endif